Detect click on OS X menu bar? - macos

I'm curious if there's a trick to detecting a click on the Menu Bar as a whole. I know I can detect a click on an NSStatusItem or NSMenu, but I am looking for events pertaining to the empty space of the Menu Bar.
Looking through the documentation, it does not seem possible. However, I wanted to know if anyone had a workaround for this functionality?

You can install a local event monitor using NSEvent addLocalMonitorForEventsMatchingMask:handler:
See the documentation located here.

Related

How to completly restore a Edit menu in Cocoa or find missing Actions like Redo

I deleted the Edit menu from my cocoa app but now I need to restore it with all the voices. I tryed to copy it from another app but it lose all the Actions... so I found myself with all the voices of the menu but they do nothing... so I started to connect all the voices in First Responder and it was working but then I noticed that some voices like "Redo" and others are not in First Responder and I don't know where to find them..
Is there a way to completly restore the Edit menu in my app? or if it is no possible anyone knows where I can find the missing Actions like Redo?
Thanks for any help - Peace - Massy
Look in the Interface Builder Object Library (Where there are buttons and other controls to drag onto your interface.)
There you will find Edit Menu Item. (Search for it if you can't see it.) You can drag it into your menu.

StatusItem menu doesn't open on hover

I've got an NSStatusItem with a menu. My problem is that when you click on for example the wifi icon, the menu appears. When I move to the right (on my mac the battery status item is there) the menu for the battery automatically appears. That's what I mean with "on hover". This behaviour is implemented in pretty much all status items and/or menu's. But my NSStatusItem doesn't implement this behaviour. I don't see an option in IB to "assign" this behaviour, so I started searching the web and all I can come up with is this:
Status Item menus don't open on hover
The "answer" here is everything but satisfying. So my question is: is this true? Aren't there any ways to create this behaviour without using private API's?
Thanks a lot in advance,
Frans

How to display my app's icon (programmatically) on the top right corner of the Mac OS X menu bar

I know Skype does it - they have a special icon register to there. And then when user click on the icon, a drop down menu will appear...
See the docs for status bar and NSStatusItem. You can also find tutorials and sample code by googling for NSStatusItem.
NSStatusItem is responsible for this.

Win32 newbie: Firefox-like find bar

Firefox has this nice find-a-text-on-the-page dialog, which is non-modal and shows up at the bottom of the window. How to do something similar using just Win32? I guess there has to edit control but do I have to position it manually on parent window WM_SIZE? How do I dismiss the dialog, i.e. how to make it disappear?
As said above, use a rebar and put an edit control and the buttons that you need on it. You'll have to manage all the rest yourself, manually (close button, showing/hiding it, etc.).
I guess that is what you call a rebar...http://msdn.microsoft.com/en-us/library/bb774373(VS.85).aspx. Google if you need more info...

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.
You can do it, apple provides a method for it popUpStatusItemMenu:
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.

Resources