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
2009-09-14 06:41:34
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
2009-09-14 12:30:45
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
2009-09-14 17:18:49
http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/Classes/NSStatusItem_Class/Reference/Reference.html#//apple_ref/occ/instm/NSStatusItem/popUpStatusItemMenu:
Jon Hess
2009-09-15 10:36:12
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
2009-09-21 02:35:03