2015-04-17 298 views
1

我想创建一个AppleScript点击菜单但我不能永远使用我,这里的脚本是什么菜单我想: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等)

+0

元: 作用:菜单项 标题: “登录为...” 说明: 帮助: 应用:SytemUIServer 元PATCH(开始于叶元素): 菜单项目“登录为。 ..“(菜单项12) 菜单(菜单1) 菜单额外(菜单栏项目2) 菜单栏(菜单栏1) 应用程序”SystemUIServer“ –

回答

4

在你的问题,你没没有指定菜单栏项目名称应用程序名称拥有菜单栏项目。那就是问题所在。

首先,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}

第三方应用,加上射灯,管理自己的菜单栏项目/图标。焦点例如:

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个字符的编辑。

+0

嗨,谢谢你的回答,菜单栏的名称“苹果连接”及其集成在“SystemUIServer” –