Applescript 单击 Mac 状态栏中的特定应用程序

See*_*van 5 testing macos applescript automation automated-tests

我有一个作为状态栏应用程序运行的 OS X 应用程序。我正在尝试进行测试自动化。有没有办法使用 Apple Script 单击状态栏应用程序?

下面给出的脚本仅适用于本机应用程序。

tell application "System Events" to tell process "SystemUIServer" to click menu bar item 1 of menu bar 1
Run Code Online (Sandbox Code Playgroud)

我正在寻找自定义应用程序上的类似功能。

jwe*_*aks 2

并非所有菜单栏附加功能(或状态图标)都可以通过 UI 脚本访问。您必须尝试是否可以通过唯一的描述或其他值来调用它们。\n尝试这样的代码,看看您是否可以弄清楚:

\n\n
tell application "System Events" to tell process "SystemUIServer"\n    tell (menu bar item 1 of menu bar 1 where description is "clock")\n        click\n        click menu item "Open Date & Time Preferences\xe2\x80\xa6" of menu 1\n    end tell\nend tell\n
Run Code Online (Sandbox Code Playgroud)\n\n

如果您在那里找不到它,您可以尝试在菜单栏 2 中找到“状态”项目。

\n