Can AppleScript be able to click the menu extra of a 3rd-party app?
Many 3rd-party apps have small menu icons at the top-right corner of the menu bar such as Evernote, iStat, Parallels Desktop and so on. I tried to write some AppleScripts to click those menu icons, but all failed.
Take "PD" for example:
tell application "System Events"
tell process "Parallels Desktop"
get properties of every menu bar item of every menu bar
end tell
end tell
I can get multiple menu items such as "Apple", "Parallels Desktop", "File", "Edit", ..., "Help", which are apparently the top-left menus of PD. Besides, a menu extra is also obtained and is described as follows:
{minimum value:missing value, orientation:missing value, position:{1338, 0}, class:menu bar item, accessibility description:"", role description:"menu extra", focused:false, title:missing value, size:{30, 22}, help:"", entire contents:{}, enabled:true, maximum value:missing value, role:"AXMenuBarItem", value:missing value, subrole:"AXMenuExtra", selected:false, name:missing value, description:""}
After verifying the position by Accessibility Inspector, I can confirm that this menu extra is the menu icon I want to click. Then I write this:
tell application "System Events"
tell process "Parallels Desktop"
click menu bar item 1 of menu bar 2
end tell
end tell
or replace the "click" statement with:
perform action "AXPress" of menu bar item 1 of menu bar 2
or with:
perform action "AXShowMenu" of menu bar item 1 of menu bar 2
All of the above codes return the same result: missing value, and no menus show up at all!
As for the System UI Elements such as "input text", "date and time", "wifi", "battery", "VPN", the click method works. BUT for 3rd-party apps, it doesn't work.
So, how to click those 3rd-party menu extras via AppleScript?
Thank you so much!!
Solution 1:
I was having an issue getting AppleScript to click on the menu extra of iTeleport Connect until I tried the following:
tell application "System Events" to tell process "iTeleport Connect"
tell (menu bar item 1 of menu bar 2)
click -- This click appears to be the important addition that allows you to drill down to the other items
click menu item "Connect" of menu 1
end tell
end tell