6

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!!

1
  • I found that some 3rd party apps -especially ones that have a custom drop down menu- seem not to be scriptable. I heard of a trick to use Automator and its "Menu Workflow > Record [Shift-Cmd-R]" watch-me-do menu item that returns some "action icons" that can next be pasted in ScriptEditor. I succeeded in recording some clicks onto Avira's menu icon that could be "repeated" from Automator – but would NOT "replay" if pasted identically into a ScriptEditor window. At least you can get an exact description of your "menu icon" through this procedure, or maybe use an Automator app in the end .... Commented Nov 18, 2018 at 17:41

1 Answer 1

2

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
3
  • The OP clearly already tried this and stated it did not work. Commented Dec 11, 2018 at 20:23
  • The addition of the lone "click" makes it work. :-) Commented Dec 11, 2018 at 20:28
  • Doesn't matter that you wrote it differently as both execute the event as tell application "System Events" to click menu bar item 1 of menu bar 2 of process "ProcessName"! Commented Dec 11, 2018 at 21:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .