Macos – Can AppleScript/osascript be used to click menu extra menu items

applescriptmacososascriptosx-mountain-lion

I have an application installed that only appears in the menu bar (as a menu extra to the right). I would like to click one of the items contained in its menu via osascript. I've found the following code snippet:

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

Sadly, it does not work. I assume I have the name of menu extra correct: "Keymando menu extra".

Best Answer

SystemUIServer only includes menu extras (the icons on the right side that can be rearranged) but not status menus (like the one Keymando uses).

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

In some applications menu bar 2 is the status menu, but tell application "System Events" to UI elements of process "Keymando" returns an empty list.

Related Question