Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 673
akaru Avatar asked Mar 21 '11 20:03

akaru


2 Answers

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];
}
like image 172
ughoavgfhw Avatar answered Nov 18 '22 07:11

ughoavgfhw


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.

like image 29
akaru Avatar answered Nov 18 '22 05:11

akaru