macoscocoakeyboard-shortcutsnsstatusbar

How to programmatically open status bar app?


I want to open my status bar app when global shortcut is fired.

Here is how I set up the statusItem:

NSMenu *appMenu=[NSMenu new];
NSMenuItem *firstItem=[NSMenuItem new];
[firstItem setView:_clickView];
[appMenu addItem:firstItem];
self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:100];
[self.statusItem setTitle:@"App"];
[self.statusItem setMenu:appMenu];

After that I use DDHotKey to respond to shortcuts. I can determine if shortcut is fired, but I do not know how to open menu as it was status bar click.

I also tried to play with NSMenu popUpContextMenu. But is seems to me, it is not the right way. The menu shows up in a new window and it is not the behaviour I am looking for.


Solution

  • NSStatusItem popUpStatusItemMenu: did the trick. I just pass it's own menu as an argument and it works.