Question

Ok I have a status menu application with a "Hide" menu item in it.

Clicking on "Hide" calls:

[[NSStatusBar systemStatusBar] removeStatusItem:statusItem]

which of course removes my application from the status bar even though it is still running.

I want my application to be re-added into the system status bar when the user "opens" my application in the Applications folder. The problem is I can't insert the piece of code to do this inside "ApplicationDidFinishLaunching" since the application is already open. So what should I do?

Was it helpful?

Solution

You could use -applicationDidBecomeActive:, though you need to distinguish between the cases where the application becomes active after it was hidden, and it became active after the user switched to a different app without hiding yours.

OTHER TIPS

Can't you just initialize that status item programmatically? This seems to work for me, even outside of applicationDidFinishLaunching:

    // Install status item into the menu bar
myStatusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
NSImage *statusImage = [NSImage imageNamed:@"Status.png"];
[myStatusItem setImage:statusImage];
NSImage *altStatusImage = [NSImage imageNamed:@"StatusHighlighted"];
[myStatusItem setAlternateImage:altStatusImage];
[myStatusItem setHighlightMode:YES];
[myStatusItem setMenu:self.myStatusMenu];
[self.myStatusMenuItem setTitle:@"Show"];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top