views:

947

answers:

1

Hey everyone.

I am in the process of writing a menubar icon for an app i'm developing. However the NSStatusBar class does not have a method which would make the icon draggable, via cmd+left mouse drag.

How do you make your menubar icon draggable with Objective-C code?

Thank you :)

+4  A: 

You can't currently do it with NSStatusBar. NSMenuExtra will behave the the way you want, but unfortunately it's not part of the part of the public Cocoa API, and from what I understand (I haven't used it myself) takes a bit of a hack to even get it working. Also NSStatusBar will be easier to integrate into an existing application, NSMenuExtra is more of a separate bundle that's loaded by the system.

In my opinion it's not a good idea to depend on private APIs to add major functionality like this to your app. I would stick with NSStatusBar, most users will be used to the behavior from other applications, and with any luck a future version of Mac OSX will allow dragging the icon the same way NSMenuExtra works.

Marc Charbonneau
http://cocoadevcentral.com/articles/000078.php is a great article about NSMenuExtras. But i also recommend the documented NSStatusItem.
mfazekas