Search code examples
macoscocoamenustatusnsstatusbar

OSX: How to "unhide" a status bar item?


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?


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.