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

6 macos applescript menubar

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

\n\n

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

\n\n

在此输入图像描述\n在此输入图像描述

\n\n

我的尝试:

\n\n

尝试1

\n\n
tell application "System Events" to tell process "Fen\xc3\xaatre"\n    tell menu bar item 1 of menu bar 1\n        click\n        click menu item "Show all" of menu 1\n    end tell\nend tell\n
Run Code Online (Sandbox Code Playgroud)\n\n

错误:

\n\n
$ osascript a.applescript \na.applescript:121:157: execution error: System Events got an error: Can\xe2\x80\x99t get menu item "Show all" of menu 1 of menu bar item 1 of menu bar 1 of process "Fen\xc3\xaatre". (-1728)\n
Run Code Online (Sandbox Code Playgroud)\n\n

请注意,当我仅运行 attemp1 的第一行和最后一行时,它运行良好,当我添加中间行时,它无法运行。

\n\n

尝试2

\n\n
ignoring application responses\n    tell application "System Events" to tell process "Fen\xc3\xaatre"\n        click menu bar item 1 of menu bar 2\n    end tell\nend ignoring\ndo shell script "killall System\\\\ Events"\ndelay 0.1\ntell application "System Events" to tell process "Fen\xc3\xaatre"\n    tell menu bar item 1 of menu bar 2\n        click menu item "a.py" of menu 1\n        -- click menu item 1 of menu 1 -- another try\n    end tell\nend tell\n
Run Code Online (Sandbox Code Playgroud)\n\n

更新(仍然出现错误)

\n\n
tell application "System Events" to tell process "Fen\xc3\xaatre"\n    get entire contents of menu bar 2\nend tell\n
Run Code Online (Sandbox Code Playgroud)\n\n

这给出:

\n\n
{menu bar item 1 of menu bar 2 of application process "Fen\xc3\xaatre" of application "System Events"}\n
Run Code Online (Sandbox Code Playgroud)\n\n

参考文献:
\n Applescript:通过 gui 脚本单击菜单栏项目
\n applescript 单击菜单栏选项
\n https://superuser.com/questions/587815/can-applescript-osascript-be-used-to-click-menu -extra-menu-items
\n Applescript 显示 Apple 菜单栏项目
\n AppleScript UI 脚本总体来说是否非常慢,或者是我的脚本,还是其他什么?
\n使用 AppleScript 单击应用程序菜单栏项目

\n\n

多谢。

\n

poi*_*tum 2

使用包标识符而不是应用程序名称:

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
Run Code Online (Sandbox Code Playgroud)

  • 为了查找捆绑列表,我使用了 `/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' /Applications/Fenêtre.app/Contents/Info.plist` (2认同)