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

Macos Applescript单击状态栏应用程序的菜单项,macos,applescript,menubar,Macos,Applescript,Menubar,我有一个名为Fenêtre的应用程序,当使用top命令查找进程名称时,它给出了名称Fene?~Btre H 我想单击其菜单栏项下名为“a.py”的项,如图所示 我的尝试: 尝试1 错误: $ 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

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

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

我的尝试:

尝试1 错误:

$ 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 更新(仍然获得错误) 这使得:

{menu bar item 1 of menu bar 2 of application process "Fenêtre" of application "System Events"}
参考文献:






非常感谢。

使用捆绑标识而不是应用程序名称:

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

另外,请尝试使用
菜单项2
之类的内容,而不是使用名称或
返回菜单1的全部内容,以找出其中的内容。如何查找捆绑标识名称<代码>“BUNDLE\u IDENTIFIER\u HERE”。无效索引。
我尝试了
。。。捆绑包标识符为“com.yoannmoinet.fenetre”
,但仍提供
系统事件获取错误:无法获取捆绑包标识符为“com.yoannmoinet.fenetre”的应用程序进程1的菜单栏项目1的菜单栏项目1的菜单项“全部显示”.
为了找到捆绑包列表,我使用了
/usr/libexec/PlistBuddy-c'Print CFBundleIdentifier'/Applications/Fenêtre.app/Contents/Info.plist
这个答案是正确的,而且有效!您所要做的就是更改选项名称并在/Applications/folder上的Info.plist上找到捆绑包标识符。从屏幕截图上看,Fenêtre似乎是一个菜单栏应用程序。在我使用不同的菜单栏应用程序进行的实验中,实际可见的菜单栏项目似乎位于
菜单栏2
,而不是
菜单栏1
。但是,对于我正在测试的应用程序,可访问性系统(system Events用来访问UI)看不到该菜单栏项的任何内容。我不知道这是我测试的应用程序特有的,还是所有菜单栏应用程序的通用。你从
获取菜单栏2的全部内容
告诉应用程序“系统事件”告诉进程“事件”获取菜单栏2的全部内容end tell
给出
{应用程序“系统事件”的应用程序进程“事件”的菜单栏2的菜单栏项1}
告诉应用程序“系统事件”告诉(包标识符为“com.yoannmoinet.fenetre”的第一个应用程序进程)获取菜单栏2的全部内容end tell end tell
给出了相同的内容
{应用程序“系统事件”的应用程序进程“Fenêtre”的菜单栏2的菜单栏项1}
是的,这大致就是我测试的应用程序的结果。这意味着菜单项无法通过这种方式访问。可能是当菜单实际打开时,这些项可以访问,但我还没有测试。我知道在菜单栏项上发出
单击
命令确实会导致它打开,但该命令直到菜单被解散,所以你不能发出后续命令来查找。它可能会使用“代码>尝试和<代码>超时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"}
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