Clicking an applications menu bar item with AppleScript -
i use time tracker mac my, well, time tracker. has menu bar item want able access via keyboard shortcut.
i found way click item gui scripting:
tell application "system events" tell process "time tracker" click menu bar item of menu bar 2 end tell
unfortunately script not return success unless acted on menu (i.e. pressing enter or esc key). if want trigger down arrow key...
tell application "system events" tell process "time tracker" click menu bar item of menu bar 2 -- hangs here forever until menu closed tell application "system events" key code 124 end tell
the script waits forever. if hit escape menu bar item closes , down arrow key triggered.
it's kind weird. need menu bar item's click not block further script execution.
any suggestions?
the click command returns after 5 seconds me. 1 workaround use ignoring application responses , terminate system events:
ignoring application responses tell application "system events" tell process "time tracker" click menu bar item 1 of menu bar 2 end tell end ignoring shell script "killall system\\ events" delay 0.1 tell application "system events" tell process "time tracker" tell menu bar item 1 of menu bar 2 click menu item 2 of menu 1 end tell end tell
related questions:
Comments
Post a Comment