5

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?

hollow7
  • 1,506
  • 1
  • 12
  • 20
  • Does this post help: http://stackoverflow.com/questions/843379/how-do-you-toggle-the-status-item-in-the-menubar-on-and-off-using-a-checkbox – petert Nov 16 '11 at 08:57

2 Answers2

3

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.

0

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"];
DenVog
  • 4,226
  • 3
  • 43
  • 72