我正在尝试为名为 F.lux 的应用程序制作一个 applescript,该应用程序单击菜单项“禁用一小时”,如下面的屏幕截图所示:
元素路径如下面的截图所示:
这是迄今为止我的代码:
tell application "System Events"
tell process "Flux"
click (menu bar item 1 of menu bar 2)
click menu item "Disable for an hour" of menu 1 of menu bar item 1 of
menu bar 2
end tell
end tell
一切都编译得很好,但是当我尝试运行脚本时,我不断收到下面的错误消息:
错误“系统事件发生错误:无法获取进程“Flux”的菜单栏 2 的菜单栏项目 1 的菜单 1。索引无效。”编号 -1719 来自进程“Flux”的菜单栏 2 的菜单栏项目 1 的菜单 1
有人能指出我哪里出了问题吗?
这对我有用,但第一次单击命令后有大约 5 秒的延迟。
tell application "System Events" to tell process "Flux"
tell menu bar item 1 of menu bar 2
click
click menu item "Disable for an hour" of menu 1
end tell
end tell
一种解决方法是使用
ignoring application responses
并在单击命令后终止系统事件:
ignoring application responses
tell application "System Events" to tell process "Flux"
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 "Flux"
tell menu bar item 1 of menu bar 2
click menu item "Disable for an hour" of menu 1
end tell
end tell
我必须做类似的脚本编写,这对我有用,尽管它不尊重层次结构(实际上是
tell application "System Events" to tell process "FortiTray"
repeat
try
click menu item "Connect" of menu 1 of menu bar 1
end try
delay 2 -- = Time to wait until next check in seconds
end repeat
end tell