jason
jason

Reputation:

how do you display an NSMenu programmatically?

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.

Upvotes: 7

Views: 2734

Answers (2)

jason
jason

Reputation:

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

Upvotes: 6

Rob Keniger
Rob Keniger

Reputation: 46020

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.

Upvotes: 0

Related Questions