applescript 单击菜单栏选项 [英] applescript click menu bar option

查看:72
本文介绍了applescript 单击菜单栏选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

元素:作用:菜单项标题:登录为……"描述 :帮助:应用:SystemUIServer元素补丁(从叶元素开始):菜单项以...登录"(菜单项 12)菜单(菜单 1)额外菜单(菜单栏项目 2)菜单栏(菜单栏 1)应用程序SystemUIServer"

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

忽略应用程序响应告诉应用程序系统事件"告诉进程SystemUIServer"单击菜单栏 1 的菜单栏项目 2结束告诉结束无视执行 shell 脚本killall System\\ Events"延迟 0.1告诉应用程序系统事件"告诉进程SystemUIServer"告诉菜单栏 1 的菜单项 1 的菜单项 12 菜单栏 1 的菜单项 2点击结束告诉结束告诉

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

解决方案

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

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

1)

告诉应用程序系统事件"告诉进程SystemUIServer" ¬到菜单栏的数量

2)

告诉应用程序系统事件"告诉进程SystemUIServer" ¬到菜单栏 1 的菜单栏项目的属性AXDescription"的值

3)

告诉应用程序系统事件"告诉进程SystemUIServer" ¬到菜单栏 2 的菜单栏项目的标题

结果应该类似于:

1) 2

2) {"Wi-Fi, 四根四根,带 WiFiName.", "Battery: Charged ", "Clock"}

3) {通知中心",缺失值}

第三方应用程序,加上 Spotlight,管理自己的菜单栏项目/图标.例如聚光灯:

告诉应用程序系统事件"告诉进程聚光灯"¬到菜单栏 1 的菜单栏项目的标题

这给你:{"Spotlight"}

如果你有咖啡因:

告诉应用程序系统事件"告诉进程咖啡因"¬到菜单栏 1 的菜单栏项目的标题

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

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

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

I want to create an AppleScript to click a menu but I can't what ever the script I using, here is the menu I want :

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"

So I did a few script, the last one was

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

Also I just realise that the position can change (some time the item I want to click is menu item 12 sometime its 10 etc.)

解决方案

In your question, you didn't specify name of the menu bar item and name of the app which owns the menu bar item. That's the problem.

First, SystemUIServer only run menu bar items/icons native to OS X. To see the icons it runs, do these three lines separately in 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

The results should look something like:

1) 2

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

3) {"Notification Center", missing value}

Third-party apps, plus Spotlight, manage its own menu bar items/icons. Spotlight for example:

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

This gives you: {"Spotlight"}

If you have Caffeine:

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

You get: {missing value}, 'cause its programer didn't bother naming the item.

So if this is third-party menu bar item you are trying to script, it's not in SystemUIServer. If you only refer to the menu bar item with position instead of its name, you cannot reliably click it every time.

McUsr inserted this line, in order to save the edit that had to be of minimum 6 characters.

这篇关于applescript 单击菜单栏选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆