【问题标题】:applescript click menu bar optionapplescript单击菜单栏选项
【发布时间】:2015-04-17 12:43:18
【问题描述】:

我想创建一个 AppleScript 来单击菜单,但我无法使用我使用的任何脚本,这是我想要的菜单:

ELEMENT :
 Role : menu item
 Title: "sign in As..."
 Description :
 Help:
 Application: SytemUIServer

ELEMENT PATCH (starting at leaf element):
 menu Item "Sign in As..." (menu item 12)
  menu (menu 1)
   menu extra (menu bar item 2)
    menu bar (menu bar 1)
      application "SystemUIServer"

所以我做了一些脚本,最后一个是

ignoring application responses
    tell application "System Events" to tell process "SystemUIServer"
        click menu bar item 2 of menu bar 1
    end tell
end ignoring
do shell script "killall System\\ Events"
delay 0.1
tell application "System Events" to tell process "SystemUIServer"
    tell menu item 12 of menu 1 of menu bar item 2 of menu bar 1
        click
    end tell
end tell

我也只是意识到位置可以改变(有时我想点击的项目是菜单项 12 有时是 10 等等)

【问题讨论】:

  • ELEMENT:角色:菜单项标题:“登录为...” 描述:帮助:应用程序:SytemUIServer ELEMENT PATCH(从叶元素开始):菜单项“登录为...” (menu item 12) menu (menu 1) menu extra (menu bar item 2) menu bar (menu bar 1) application "SystemUIServer"

标签: select applescript menubar


【解决方案1】:

在您的问题中,您没有指定 菜单栏项的名称拥有该菜单栏项的应用程序的名称。这就是问题所在。

首先,SystemUIServer 仅运行 OS X 原生的菜单栏项目/图标。要查看它运行的图标,请在 Script Editor 中分别执行这三行。

1)

tell application "System Events" to tell process "SystemUIServer" ¬
to number of menu bars

2)

tell application "System Events" to tell process "SystemUIServer" ¬
to value of attribute "AXDescription" of menu bar items of menu bar 1

3)

tell application "System Events" to tell process "SystemUIServer" ¬
to title of menu bar items of menu bar 2

结果应该类似于:

1) 2

2){"Wi-Fi, four of four bars, with WiFiName.", "Battery: Charged ", "Clock"}

3){"Notification Center", missing value}

第三方应用程序以及 Spotlight 管理自己的菜单栏项目/图标。以聚光灯为例:

tell application "System Events" to tell process "Spotlight" ¬
to title of menu bar items of menu bar 1

这会给你:{"Spotlight"}

如果你有Caffeine:

tell application "System Events" to tell process "Caffeine" ¬
to title of menu bar items of menu bar 1

你会得到:{missing value},因为它的程序员没有费心为这个项目命名。

因此,如果这是您尝试编写脚本的第三方菜单栏项,则它不在 SystemUIServer 中。如果您仅使用位置而不是名称来引用菜单栏项,则无法每次都可靠地单击它。

McUsr 插入了这一行,以保存必须至少为 6 个字符的编辑。

【讨论】:

  • 您好,感谢您的回答,菜单栏的名称是“apple connect”并集成在“SystemUIServer”中
猜你喜欢
  • 2013-05-05
  • 1970-01-01
  • 1970-01-01
  • 2021-11-25
  • 2019-03-21
  • 2022-06-23
  • 2022-08-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多