I use Mac 版时间追踪器 https://code.google.com/p/time-tracker-mac/作为我的时间追踪器。它有一个菜单栏项目,我希望能够通过键盘快捷键访问它。
我找到了一种使用 GUI 脚本来单击该项目的方法:
tell application "System Events" to tell process "Time Tracker"
click menu bar item of menu bar 2
end tell
不幸的是,除非我在菜单上执行操作(即按 Enter 或 Esc 键),否则脚本不会返回成功。所以如果我想触发向下箭头键......
tell application "System Events" to tell process "Time Tracker"
click menu bar item of menu bar 2
-- hangs here forever until menu is closed
tell application "System Events" to key code 124
end tell
脚本只是永远等待。如果我点击退出,菜单栏项目将关闭,然后只有向下箭头键才会被触发。
这有点奇怪。我只需要点击菜单栏项目即可not阻止进一步的脚本执行。
有什么建议么?
对我来说,单击命令大约 5 秒后返回。一种解决方法是忽略应用程序响应并终止系统事件:
ignoring application responses
tell application "System Events" to tell process "Time Tracker"
click menu bar item 1 of menu bar 2
end tell
end ignoring
do shell script "killall System\\ Events"
delay 0.1
tell application "System Events" to tell process "Time Tracker"
tell menu bar item 1 of menu bar 2
click menu item 2 of menu 1
end tell
end tell
相关问题:
- Applescript:通过 gui 脚本单击菜单栏项目 https://stackoverflow.com/questions/16492839
- AppleScript UI 脚本总体上是否非常慢,或者是我的脚本,还是其他原因? https://stackoverflow.com/questions/16365281
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)