我有一个名为Fenêtre的应用程序,在使用top
命令查找进程名称时,它给出了名称Fene?~Btre H
。
我想要点击菜单栏中的“a.py”项目,如下图所示。
我的尝试:
尝试1
tell application "System Events" to tell process "Fenêtre"
tell menu bar item 1 of menu bar 1
click
click menu item "Show all" of menu 1
end tell
end tell
错误:
$ osascript a.applescript
a.applescript:121:157: execution error: System Events got an error: Can’t get menu item "Show all" of menu 1 of menu bar item 1 of menu bar 1 of process "Fenêtre". (-1728)
注意,当我只运行attemp1的第一行和最后一行时,它可以正常运行,但是当我添加中间行时,它无法运行。
尝试2
ignoring application responses
tell application "System Events" to tell process "Fenêtre"
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 "Fenêtre"
tell menu bar item 1 of menu bar 2
click menu item "a.py" of menu 1
-- click menu item 1 of menu 1 -- another try
end tell
end tell
更新(仍然出现错误)
tell application "System Events" to tell process "Fenêtre"
get entire contents of menu bar 2
end tell
这将会得到:
{menu bar item 1 of menu bar 2 of application process "Fenêtre" of application "System Events"}
参考文献:
Applescript:通过gui脚本单击菜单栏项目
applescript点击菜单栏选项
https://superuser.com/questions/587815/can-applescript-osascript-be-used-to-click-menu-extra-menu-items
Applescript显示Apple菜单栏项目
AppleScript UI脚本一般很慢吗,还是我的脚本或其他原因?
使用AppleScript单击应用程序的菜单栏项目
非常感谢。
tell application "System Events" to tell process "Fenêtre" get entire contents of menu bar 2 end tell
gives{menu bar item 1 of menu bar 2 of application process "Fenêtre" of application "System Events"}
- user8864088tell application "System Events" tell (first application process whose bundle identifier is "com.yoannmoinet.fenetre") get entire contents of menu bar 2 end tell end tell
gives the same thing{menu bar item 1 of menu bar 2 of application process "Fenêtre" of application "System Events"}
- user8864088