Reputation: 1506
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?
Upvotes: 5
Views: 982
Reputation: 4286
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"];
Upvotes: 0
Reputation:
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.
Upvotes: 3