Skip to content

Instantly share code, notes, and snippets.

@designbyadrian
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save designbyadrian/652d1f5b11568838f70d to your computer and use it in GitHub Desktop.
Save designbyadrian/652d1f5b11568838f70d to your computer and use it in GitHub Desktop.
Send keystroke command to Mac OS application
-- run with "osascript keystroke.scpt APPNAME KEY MODIFIER"
on run params
set frontApp to (path to frontmost application as text)
set appl to item 1 of params
set keyy to item 2 of params
if frontApp is not equal to appl then
tell application appl
reopen
activate
end tell
repeat until application appl is running
delay 1
end repeat
delay 0.5
end if
if (count of params) is greater than 2 then
set m to item 3 of params
if m is equal to "command" then
set modifier to command down
else if m is equal to "shift" then
set modifier to shift down
else if m is equal to "option" then
set modifier to option down
else if m is equal to "control" then
set modifier to control down
end if
tell application "System Events" to keystroke keyy using modifier
else
tell application "System Events" to keystroke keyy
end if
(*
LEFT: (key code 123)
RIGHT: key code 124)
UP: (key code 126)
DOWN: (key code 125)
*)
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment