Bla*_*ilk 12 macos applescript
我正在尝试为名为F.lux的应用程序制作一个应用程序,点击菜单项"禁用一小时",如下面的屏幕截图所示:
元素路径如下面的屏幕截图所示:
这是我到目前为止的代码:
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
Run Code Online (Sandbox Code Playgroud)
一切都编译好,但是当我尝试运行脚本时,我不断收到以下错误消息:
错误"系统事件出错:无法获取进程\"Flux \"菜单栏2的菜单栏项目1的菜单1.索引无效." 从流程"Flux"的菜单栏2的菜单栏项目1的菜单1开始编号-1719
有人可以确定我在哪里出错吗?
Lri*_*Lri 29
这对我有用,但是在第一次单击命令后大约有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
Run Code Online (Sandbox Code Playgroud)
一种解决方法是ignoring application responses
在click命令后使用和终止系统事件:
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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
14633 次 |
最近记录: |