AppleScript单击状态栏应用程序的菜单项

时间:2018-10-17 02:19:14

标签: macos applescript menubar

我有一个名为Fenêtre的应用程序,当使用top命令查找进程名称时,它的名称为Fene?~Btre H

我想单击菜单栏项下的“ a.py”项,如图所示。

enter image description here enter image description here

我的尝试

尝试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: on clicking Menu Bar item via gui script
applescript click menu bar option
https://superuser.com/questions/587815/can-applescript-osascript-be-used-to-click-menu-extra-menu-items
Applescript to show Apple menu bar items
Is AppleScript UI Scripting very slow in general, or is it my script, or something else?
Clicking an applications menu bar item with AppleScript

非常感谢。

1 个答案:

答案 0 :(得分:0)

使用捆绑包标识符代替应用名称:

tell application "System Events"
    tell (first application process whose bundle identifier is "BUNDLE_IDENTIFIER_HERE")
        tell menu bar item 1 of menu bar 1
            click
            click menu item "Show all" of menu 1
        end tell
    end tell
end tell