我安装了一个应用程序,它只出现在菜单栏中(作为右侧的菜单附加项)。我想通过 osascript 单击其菜单中包含的其中一个项目。我找到了以下代码片段:
osascript -e '
tell application "System Events"
tell process "SystemUIServer"
tell (1st menu bar item of menu bar 1 whose value of attribute "AXDescription" is "keymando menu extra")
perform action "AXPress" of menu item "Edit Config" of menu 1
end tell
end tell
end tell
遗憾的是,它不起作用。我认为我的菜单附加名称是正确的:“Keymando 菜单附加”。
答案1
SystemUIServer 仅包含菜单附加功能(右侧可以重新排列的图标),但不包含状态菜单(如 Keymando 使用的菜单)。
tell application "System Events" to tell process "SystemUIServer"
tell (menu bar item 1 of menu bar 1 where description is "clock")
click
click menu item "Open Date & Time Preferences…" of menu 1
end tell
end tell
在某些应用程序中menu bar 2
是状态菜单,但tell application "System Events" to UI elements of process "Keymando"
返回一个空列表。
答案2
它可能在那里,这会在临时文件夹中写入一个列表,您可以通过它来查找“句柄”。
`osascript -sso > /private/tmp/StatusBarItems <&- <<EOF
tell application "System Events"
get properties of every menu bar item of every menu bar of process "SystemUIServer"
end tell
EOF`
或者你可以尝试
` osascript -sso > /private/tmp/SU_reLoad <&- <<BUTTON
tell application "System Events"
click menu bar item 1 of menu bar 2 of application process "SystemUIServer"
end tell
BUTTON`
不幸的是,我想要的那个不在那里......“非脚本化”应用程序的“退出全屏按钮”......约翰
答案3
我能够使用
tell application "System Events" to tell process "Google Chrome" to tell menu bar 2
click (first menu bar item where help is "Google Hangouts")
end tell