Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I make a draggable Menubar icon for Mac OS X

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 :)

like image 816
Brock Woolf Avatar asked Dec 30 '22 05:12

Brock Woolf


1 Answers

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 OS X will allow dragging the icon the same way NSMenuExtra works.

like image 168
Marc Charbonneau Avatar answered Jan 18 '23 15:01

Marc Charbonneau