I want to make a preference for hiding the Dock icon and showing an NSStatusItem
. I can create the StatusItem but I don't know how to remove the icon from Dock. :-/
Any ideas?
1) Click the Apple icon to open the menu. 2) In the menu, select System Preferences. 3) Select Dock & Menu Bar from the next window. 4) In the window that opens, select the Automatically hide and select the Dock option.
I think you are looking for the LSUIElement
in the Info.plist
LSUIElement (String). If this key is set to “1”, Launch Services runs the application as an agent application. Agent applications do not appear in the Dock or in the Force Quit window. Although they typically run as background applications, they can come to the foreground to present a user interface if desired.
See a short discussion here about turning it on/off
You can use what is called Activation Policy:
// The application is an ordinary app that appears in the Dock and may // have a user interface. [NSApp setActivationPolicy: NSApplicationActivationPolicyRegular]; // The application does not appear in the Dock and does not have a menu // bar, but it may be activated programmatically or by clicking on one // of its windows. [NSApp setActivationPolicy: NSApplicationActivationPolicyAccessory]; // The application does not appear in the Dock and may not create // windows or be activated. [NSApp setActivationPolicy: NSApplicationActivationPolicyProhibited];
// The application is an ordinary app that appears in the Dock and may // have a user interface. NSApp.setActivationPolicy(.regular) // The application does not appear in the Dock and does not have a menu // bar, but it may be activated programmatically or by clicking on one // of its windows. NSApp.setActivationPolicy(.accessory) // The application does not appear in the Dock and may not create // windows or be activated. NSApp.setActivationPolicy(.prohibited)
This should hide the dock icon.
NSRunningApplicationActivationPolicy
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With