tags:

views:

152

answers:

2

I wrote a little app that lives in the NSStatusBar. I want to have a global shortcut that when hit, the menu bar's content is displayed, exactly like the behavior of spotlight. I have added a global key shortcut to my application, but I am unable to get the meun bar to display. How can I do this? I tried with "popUpContextMenu" , but that method displays the menu in the bottom left hand corner, I want the menu to open up right under the NSStatusBar menu icon.

A: 

I don't think there is a supported way to do this without perhaps using the Accessibility framework to simulate a click on your status item. Regardless, it's probably not a good idea to abuse a menu in this way.

The Spotlight menu bar item does not use an NSMenu, it uses a custom window/view. You might consider going this route if you have some sort of custom view to display.

Rob Keniger
Are you sure? Accessibility Inspector says it's an AXMenu with AXMenuItems in it, and I'm not sure they'd want to re-implement that. Menus are damned tricky to get working the same way twice.
Peter Hosey
I don't think what I am doing is considered abuse, I want to have the exact same functionality as help and spotlight. I can do it without using nsmenu if its possible, I thought they were using nsmenu also.
jason
+2  A: 

You can do it, apple provides a method for it "popUpStatusItemMenu"

jason
http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/Classes/NSStatusItem_Class/Reference/Reference.html#//apple_ref/occ/instm/NSStatusItem/popUpStatusItemMenu:
Jon Hess
One issue I found though is that it does not highlight the icon in the menubar like spotlight does when you click on it.
jason