objective-cmacosnsstatusitemnsstatusbar

NSStatusItem reordering along Status Bar


I am trying to add a functionality to my status bar app for Mac OS X. I would like to be able to move my item along the bar, as you can do for the native OS tools like the Bluetooth or the WiFi icon.

Cheers


Solution

  • What you are looking for is NSMenuExtra and not NSMenuItem.

    Apple uses NSMenuExtra for the system menu icons including Wi-Fi and Bluetooth. Although it looks similar to the regular NSMenuItem, NSMenuExtra has some special features, notably to keep their relative order after rebooting, and Command-Draggable by user.

    Unfortunately, NSMenuExtra is totally undocumented, so if you are targeting the Mac App Store, it's better for you to stick with the standard NSMenuItem. Otherwise, there is a bunch of tutorials about how to create an NSMenuExtra. For example, here are two of them: