Last active
August 29, 2015 14:16
-
-
Save henrytao-me/473c80a6383dc475356a to your computer and use it in GitHub Desktop.
AppScript sample
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
#!/bin/bash | |
osascript <<- APPLESCRIPT | |
############################################## | |
# utilities | |
############################################## | |
on appIsRunning(appName) | |
tell application "System Events" to (name of processes) contains appName | |
end appIsRunning | |
on menu_click(mList) | |
local appName, topMenu, r | |
if mList's length < 3 then error "Menu list is not long enough" | |
set {appName, topMenu} to (items 1 through 2 of mList) | |
set r to (items 3 through (mList's length) of mList) | |
tell app "System Events" to my menu_click_recurse(r, ((process appName)'s ¬ | |
(menu bar 1)'s (menu bar item topMenu)'s (menu topMenu))) | |
end menu_click | |
on menu_click_recurse(mList, parentObject) | |
local f, r | |
set f to item 1 of mList | |
if mList's length > 1 then set r to (items 2 through (mList's length) of mList) | |
tell app "System Events" | |
if mList's length is 1 then | |
click parentObject's menu item f | |
else | |
my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f))) | |
end if | |
end tell | |
end menu_click_recurse | |
############################################## | |
# main | |
############################################## | |
if appIsRunning("Gideros Studio") then | |
tell application "Gideros Studio" | |
quit | |
end tell | |
delay 2 | |
end if | |
tell application "Gideros Studio" to activate | |
menu_click({"Gideros Studio", "File", "Recent Projects", 1}) | |
tell application "Gideros Studio" to activate | |
tell application "System Events" to tell process "Gideros Studio" | |
keystroke "r" using command down | |
end tell | |
# This also works | |
tell application "System Events" | |
tell process "Gideros Studio" | |
tell menu bar 1 | |
tell menu bar item "File" | |
tell menu "File" | |
tell menu item "Recent Projects" | |
tell menu "Recent Projects" | |
click menu item 1 | |
end tell | |
end tell | |
end tell | |
end tell | |
end tell | |
end tell | |
end tell | |
APPLESCRIPT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment