Last active
May 26, 2024 20:55
-
-
Save alexlmiller/643291c598401c8392eb6eff1045dc01 to your computer and use it in GitHub Desktop.
Google Slides Presenter Mode Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Automatically set up Google Slides Presenter Mode w/ no window dragging between monitors | |
-- this will move your presentation window to your secondary monitor, your speaker notes to your primary, and activate full screen on the presentation | |
-- The monitor sizing values are hardcoded for a Macbook/Pro with your second monitor arranged to the right | |
-- other configurations may require tweaking the settings | |
use AppleScript version "2.4" -- Yosemite (10.10) or later | |
use framework "Foundation" | |
use framework "AppKit" | |
use scripting additions | |
-- Function to get screen bounds | |
on getScreenBounds(screenIndex) | |
set screenArray to current application's NSScreen's screens() | |
set theScreen to item screenIndex of screenArray | |
set theFrame to theScreen's frame() as list | |
set x to item 1 of (item 1 of theFrame) as number | |
set y to item 2 of (item 1 of theFrame) as number | |
set width to item 1 of (item 2 of theFrame) as number | |
set height to item 2 of (item 2 of theFrame) as number | |
return {x as integer, y as integer, width as integer, height as integer} | |
end getScreenBounds | |
-- Get bounds of primary and secondary monitors | |
set primaryMonitorBounds to getScreenBounds(1) | |
set secondaryMonitorBounds to getScreenBounds(2) | |
tell application "Google Chrome" | |
activate | |
-- Get the list of windows and their titles | |
set windowList to every window | |
set windowTitles to {} | |
repeat with chromeWindow in windowList | |
set end of windowTitles to title of chromeWindow | |
end repeat | |
end tell | |
-- Prompt user to select a window | |
set selectedWindow to (choose from list windowTitles with prompt "Select the Google Chrome window to move:" without multiple selections allowed and empty selection allowed) | |
-- If user cancels the selection, stop the script | |
if selectedWindow is false then return | |
-- Find the index of the selected window | |
set selectedWindowTitle to item 1 of selectedWindow | |
set selectedIndex to -1 | |
repeat with i from 1 to count of windowTitles | |
if item i of windowTitles is selectedWindowTitle then | |
set selectedIndex to i | |
exit repeat | |
end if | |
end repeat | |
if selectedIndex is -1 then return -- If the window is not found, stop the script | |
tell application "Google Chrome" | |
activate | |
-- Get a reference to the selected window | |
set originalWindow to item selectedIndex of windowList | |
-- Bring the selected window to the front | |
set index of originalWindow to 1 | |
end tell | |
-- Use System Events to move and resize the window | |
tell application "System Events" | |
tell process "Google Chrome" | |
set frontmost to true | |
-- Move the window to the secondary monitor and set to 1024x768 | |
tell (window 1) to set {position, size} to {{item 1 of secondaryMonitorBounds, item 2 of secondaryMonitorBounds}, {1024, 768}} | |
end tell | |
end tell | |
-- Delay to ensure the window is moved | |
delay 0.5 | |
-- Send the cmd + enter keystroke | |
tell application "System Events" | |
key code 36 using {command down} -- Send Enter key with Command modifier | |
end tell | |
-- Delay before sending the 's' keystroke | |
delay 0.75 | |
-- Send the 's' keystroke | |
tell application "System Events" | |
keystroke "s" | |
end tell | |
-- Delay after sending the 's' keystroke | |
delay 0.25 | |
-- Get the latest list of windows after the 's' keystroke | |
tell application "Google Chrome" | |
set windowList to every window | |
set presenterWindow to missing value | |
repeat with chromeWindow in windowList | |
if (title of chromeWindow) starts with "Presenter view" then | |
set presenterWindow to chromeWindow | |
exit repeat | |
end if | |
end repeat | |
if presenterWindow is not missing value then | |
set bounds of presenterWindow to {item 1 of primaryMonitorBounds, item 2 of primaryMonitorBounds, item 3 of primaryMonitorBounds, item 4 of primaryMonitorBounds} | |
end if | |
end tell | |
-- Delay to ensure the window is in place | |
delay 0.5 | |
-- Bring the original window back to the front | |
tell application "Google Chrome" | |
activate | |
-- Ensure the original window is at the front | |
set index of originalWindow to 1 | |
end tell | |
-- Set the original window to full screen using Command + Control + f | |
tell application "System Events" | |
tell process "Google Chrome" | |
set frontmost to true | |
delay 0.5 | |
-- Fullscreen the original window | |
keystroke "f" using {command down, control down} | |
end tell | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment