Skip to content

Instantly share code, notes, and snippets.

@jdmonaco
Created August 25, 2013 17:20
Show Gist options
  • Save jdmonaco/6335110 to your computer and use it in GitHub Desktop.
Save jdmonaco/6335110 to your computer and use it in GitHub Desktop.
For browser-based presentations and other uses, it is useful to control browser navigation from outside the browser. This Applescript can be run from the command line or even other scripts (e.g., a python daemon that receives remote events) to send arrow key events to the currently active Chrome window. Optionally specify "command" to send a com…
#!/usr/bin/osascript
on run argv
set browser to "Chrome"
set leftKey to 123
set upKey to 126
set downKey to 125
set rightKey to 124
set usageString to "Usage: chrome_navigate.scpt [command] left|right|up|down"
if (length of argv = 1) then
set keyName to item 1 of argv
set commandDown to 0
else if (length of argv = 2 and item 1 of argv = "command") then
set keyName to item 2 of argv
set commandDown to 1
else
return usageString
end if
if (keyName = "left") then
set keyCode to leftKey
else if (keyName = "right") then
set keyCode to rightKey
else if (keyName = "up") then
set keyCode to upKey
else if (keyName = "down") then
set keyCode to downKey
else
return usageString
end if
tell application browser
activate
tell application "System Events" to tell process browser
if (commandDown = 1) then
key code keyCode using {command down}
else
key code keyCode
end if
end tell
end tell
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment