How to create a helper application (LSUIElement) that also has a (removable) dock icon
Asked Answered
B

2

7

I've submitted a helper application (using LSUIElement)to the Mac App Store. I was under the false impression that the App Store install process would put a dock icon for helper apps.

How can I create a dock icon that the user could remove, while the status bar app runs independently (like the popular app Caffeine)? Do I need to create a non-LSUIElement app that loads the LSUIElement app, or is there a better way?

Bibliopegy answered 21/3, 2011 at 20:0 Comment(1)
See my comment to similar SO question: https://mcmap.net/q/235042/-how-to-hide-the-dock-icon. Tested on macOS 11.Panpipe
B
1

Apparently I was misinformed by my app reviewer (two of them actually). The dock icon is created for you by the install process. Pressing the issue, I was able to get the app through the review process.

Bibliopegy answered 24/3, 2011 at 1:31 Comment(1)
This now behaves differently in Lion, where no icon is created in the Dock, only in LaunchPad.Bibliopegy
P
24

Instead of using LSUIElement, use NSApplication's setActivationPolicy: method. By default, the application will have a dock icon, but by changing the activation policy to NSApplicationActivationPolicyAccessory, you get the same effect as LSUIElement while being able to change it programatically (the documentation for NSApplicationActivationPolicyAccessory says it is equivalent to LSUIElement=1).

- (void)applicationDidFinishLaunching:(NSApplication *)app {
    if([[NSUserDefaults standardUserDefaults] boolForKey:@"HideDockIcon"])
        [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
}
Pallette answered 21/3, 2011 at 22:5 Comment(6)
Would that allow the user to remove the icon from the dock while the app is running?Bibliopegy
Yes, you just need to call setActivationPolicy: whenever you want to change it.Pallette
-1: doc says "Currently, NSApplicationActivationPolicyNone and NSApplicationActivationPolicyAccessory may be changed to NSApplicationActivationPolicyRegular, but other modifications are not supported."Devilfish
Richard is correct, you can't programmatically set the policy to NSApplicationActivationPolicyAccessory, but you can go the other way with it: set LSUIElement to 1 in the .plist, and then (optionally) set the policy to NSApplicationActivationPolicyRegular to show a dock icon.Glacial
NSApplicationActivationPolicyAccessory did not work for me but NSApplicationActivationPolicyProhibited did.Craver
The header files say diffrently now: "In OS X 10.9, any policy may be set;" The docs still have @Richards comment.Chor
B
1

Apparently I was misinformed by my app reviewer (two of them actually). The dock icon is created for you by the install process. Pressing the issue, I was able to get the app through the review process.

Bibliopegy answered 24/3, 2011 at 1:31 Comment(1)
This now behaves differently in Lion, where no icon is created in the Dock, only in LaunchPad.Bibliopegy

© 2022 - 2024 — McMap. All rights reserved.