0

I created a macOS Application which only runs in the Menubar.

My Menubar Application

In Xcode I added a Shortcut for some of the NSMenuItem with the Key Equivalent Property in the Inspector.

In this Case it is Shift+F4 and Shift+F5 Xcode Screenshot

The Shortcuts do work, but only, when the menu is opened. I guess this is because, the application is in the background for the rest of the time.

How can I get the shortcuts work, even when the menu is not open?

The Allowed When Hidden-Checkbox won't work. I assume it refers to the item itself, which can be marked as hidden.

Any ideas and suggestions will be greatly appreciated.

amiroo
  • 91
  • 10
  • Does this answer your question? [Cocoa Key Equivalent in Menu is not working](https://stackoverflow.com/questions/5785250/cocoa-key-equivalent-in-menu-is-not-working) – Willeke Sep 20 '20 at 10:26

1 Answers1

1

It looks like you are using NSStatusItem.

The operating system passes key events that it doesn't handle to the front application, which compares them to any key equivalents in its main menu and current window. They are not compared to items in the status bar, and since the status bar is actually a different application, it won't matter that your application is in the foreground. When you have the menu open, it is the window in focus. This is why it works in those circumstances.

I'm answer this from another post. Please refer that post for more detail.

  • Thank you! This is the perfect explanation, why it behaves like that. – amiroo Sep 19 '20 at 20:26
  • As per my observation MainMenu and NSStatusBar are conceptually different. When your app is active, the main menu will be visible, but in case of Status bar, it is always visible. So, this status bar item only active when user press it. – Arafat Hossain Sep 20 '20 at 07:53