2

Is it possible to create a hotkey (or other trigger) that opens a menubar app? I don't mean launch. I mean, cause the menubar app to display its contents.

Let's say, for example, I wanted to create a hotkey to open a menubar weather app. Can this be done?

The app I'm trying to open is open source on Github, so I'm open to coding the trigger into the app if need be, but I have no clue how to do that, which means I'd prefer a simpler solution.

I'm using Mountain Lion.

2

You can assign a shortcut to a script like this:

ignoring application responses
    tell application "System Events" to tell process "QuickHue"
        click menu bar item 1 of menu bar 1
    end tell
end ignoring

There is a bug where clicking some status menu items causes scripts to be blocked for about 5 seconds. One workaround is to terminate System Events after the click command:

launch application "System Events"
delay 0.2
ignoring application responses
    tell application "System Events" to tell process "Time Tracker"
        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 "Time Tracker"
    tell menu bar item 1 of menu bar 2
        click menu item 2 of menu 1
    end tell
end tell

The first two lines are needed when System Events is not already running. System Events supports sudden termination, so it should be safe to even send it a KILL signal.

| improve this answer | |
  • Thank you SO much. This was exactly what I needed. There's a bug in OSX where you can assign hotkeys to menubar app items, but the hotkeys won't work since a menubar app runs in the background. In other words, you have to click the menubar app to open it before the hotkeys can function. I consider it a bug anyway! Your code solved the problem 100%. THANK YOU!!! – 2oh1 May 26 '13 at 23:52
  • I'm trying to do this for CopyClip, but it seems access is denied. Do you know if there is any way around this? – juil Jun 8 '16 at 12:07

You must log in to answer this question.

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