MacOS – Hotkey to menubar app in Mavericks

keyboardmacosmenu bar

I have Mountain App running in my menu bar (it is an app that allows you to quickly mount and unmount drives attached to your computer). I would like to create a simple script that calls up the menu on the app (which runs only on the menu bar). I tried to follow the instructions and code found here: Create hotkey to open a menubar app?, replacing the name of the app where relevant

launch application "System Events"
  delay 0.2
  ignoring application responses
    tell application "System Events" to tell process "Mountain"
      click menu bar item 1 of menu bar 2
    end tell
  end ignoring

  do shell script "killall System\\ Events"
  delay 0.1
  tell application "System Events" to tell process "Mountain"
    tell menu bar item 1 of menu bar 2
      click menu item 2 of menu 1
    end tell
  end tell

but it did not work for me, giving me an error in Applescript:

error "System Events got an error: Can’t get menu 1 of menu bar item 1 of menu bar 1 of process \"Mountain\". Invalid index."
    number -1719 from menu 1 of menu bar item 1 of menu bar 1 of process "Mountain"

Playing around with the menu and other code pieces never got the app to activate the menu. I also tried creating a "Watch Me Do" applescript, but it will only work in automator and I couldn't get it to work globally or in any other app.

I am not a coder or programmer, so rely on some level of creativity and googling around to figure this stuff out. Anyone have a suggestion? It seems like such a simple thing to do, but my searches have found that it is not.

EDIT: I have seen the tool clickclick suggested elsewhere as a way to accomplish a mouse click. However, my understanding is that for clickclick to work, the exact coordinates of Mountain in the menu bar would need to stay the same. Is that a correct assumption in this case? If I recall, those icons in the menu bar change location on every restart or if a menu app is quit.

Best Answer

The problem in this case seems to be that Mountain.app is not a "proper" part of the menu bar, at least as far as "System Events" is concerned.

You can see this also when you use (fn+) ctrl+F8; this should put keyboard focus on the status menus, so that you can navigate them with the arrow keys. Some extra menu items (e.g. iStat menus) can be selected this way, while others can not. This, I believe, translates to accessibility with AppleScript via "System Events".