How do I launch Play-in-window from AppleScript
-
30-05-2021 - |
Question
I'd like automatically launch Keynote's "Play->Play slideshow in window" feature. There's no predefined shortcut. Can that be done from AppleScript? How? Thanks.
Solution
You can define custom keyboard shortcuts for pretty much erverything via System Preferences.
Open the "System Preferences" app ➔ "Keyboard" preferences ➔ "Shortcuts" pref pane ➔ App Shortcuts. Click the Plus (+) button.
Choose Keynote from the "Application:" list. Enter the name of the menu title, in this case "Play Slideshow in Window" exactly as it appears in the menu item (spaces, upper/lower case etc.). Enter a keyboard shortcut (Control-Option-Command-W in the screenshot below). Click the "Add" button.
Tadaaa! :) Custom keyboard shortcut in Keynote.
You can then automate this via AppleScript just like with "default" keyboard shortcuts, like so:
tell application "Keynote"
activate
tell application "System Events"
keystroke "w" using {control down, option down, command down}
end tell
end tell
(The keystroke in the script is corresponding to the example used above.)
Please remember that you have to allow the respective script editor/compiled script app to control the computer in the Accessibility settings pane in "Security & Privacy" ➔ "Privacy" settings so that the app can send keystrokes.