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.

  • AppleScript coding is on-topic here so let's see whether somebody has a solution. It might help if you edit the question to add the code you are trying to run (reduced to the critical part if possible). – nohillside Jun 24 '14 at 9:05
  • Patrix, unfortunately I'm not much of a coder. So I don't have much to show except the code from the above linked page and my feeble attempts to insert "Mountain" in place of the other named app. – SFH Jun 25 '14 at 6:19
  • Then do so please, it's much easier to help you that way. – nohillside Jun 25 '14 at 7:42
  • First, I tried this: ignoring application responses tell application "System Events" to tell process "Mountain" click menu bar item 1 of menu bar 1 end tell end ignoring That did nothing. – SFH Jun 25 '14 at 17:16

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".

  • That is an interesting point. But the only ones I can focus on using (fn+) ctrl+F8 are apple status menu items. I have a bunch of other menu apps up there DriveGenius, Choosy, ClamXAV, f.lux, Mountain, Boom, Xmarks, Quicksilver, none of them are accessible with the built in shortcut. I find it hard to believe that there is no way to do this! – SFH Jun 25 '14 at 6:17
  • @ShadyHakim iStat menus for example is accessible with GUI scripting (try running tell application "System Events" to tell process "SystemUIServer" to get value of attribute "AXDescription" of every menu bar item of menu bar 1 to check which menu extras are). I think it would be easier for you to ask what function you're trying to trigger (connecting / ejecting multiple drives, …) as there's probably a scripting solution for it. – Asmus Jun 25 '14 at 6:32
  • Thanks, Asmus. I'll check that out when I get home. The reason I am wanting to activate that menu is because it quickly gives me an at a glance perspective on what drives are or aren't mounted. I already have several scripts for mounting and unmounting the drives I regularly use (including one I've successfully mapped to my eject button for unmounting my optibay HD with a script I hobbled together and hotkeyed with Quicksilver). – SFH Jun 25 '14 at 16:57
  • Yes, none of the menubar apps I listed are in the results. Now what? – SFH Jun 26 '14 at 3:01
  • Output was: {"Messages", "time machine", "bluetooth", "Wi-Fi, four of four bars, with 28th Street (N).", "system sound volume", "Battery: Charged ", "text input", "Clock"} – SFH Jun 26 '14 at 3:17

You must log in to answer this question.

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