6
votes

If you are using DropBox on MacBook you must have seen that once we finish with registration process. It closes the main window application and removes it self from dock item yet the application is running from status menu.


Visual:

enter image description here


What I have done so far :

  • My application runs perfectly with show NSWindow
  • When I login from my front application window I am able to create a status menu icon with popover
  • In this step I want to remove the NSWindow and Dock Icon yet the application should be accessible from status menu.

How to achieve this?

FYI : I am not expecting any code, just understanding or a quick hint. I will figure out the rest :)


Resource I am referring to,

Later I will configure my app for launchd. So at system startup it can launch and shows it self in status menu. Now I am I looking at a good resource(Of course its good because its Apple Doc) but as I am a naive programmer, does anyone have a good example link? which shows how to add application in launched?

EDIT:

I will be following this tutorial to add into startup, later user can change their preferences if they want, They can choose turn on my app or turn off on startup

3
You shouldn't use launchd you should add your app as a login item...Teak
That tutorial works, however is outdated. I believe there is a better way of doing it, but I cant remember how. :)Teak
Okay found the up to date way... It works on 10.6.6 or later: LinkTeak
@Teak, That is really helpful, I could not up vote multiple times here so I checked your other answers and up voted lol. Thanks again!TeaCupApp
No problem, I'm glad I remembered...Teak

3 Answers

4
votes

To run your app as a status menu only, you add one of the following keys to your info.plist file:

Application is agent (UIElement)

or:

Application is background only

As for switching between the two, Im not sure the best way, but I would suggest making the setup process its own app. (An app with an icon and window) You would than contain the app inside your menu item app, and automatically launch it when the user launches the program...

2
votes

As Teak mentioned you want the "Application is agent (UIElement)" key in your info.plist. This key means you won't have a dock icon... which is what you want. However there is no need to use the "Application is background only" key. This key prevents you from putting any windows on the screen, which is unnecessary. So I would leave this key out.

In general setup your app so no window automatically is shown at startup. Do some sort of check at launch to see if configuration is needed. If it is then make your configuration window visible. You can even have a "configuration..." menu item in your status menu so your user can pop open the config window any time needed. It's really very simple, but just don't use the "Application is background only" info.plist key.

By the way, it's a little difficult to make a window come to the front. The trick is to make your application come frontmost first like this...

[NSApp activateIgnoringOtherApps:YES];
[someWindow makeKeyAndOrderFront:nil];
0
votes

Usually the situation mentioned in the dropbox sample solved using two separate application, one for the menu and one for the other ui part (that has the mentioned dock icon f.e.) and the two process cooperate via f.e. ipc.

doing the same in one app is a bit tricky you can find my detail about that here

Cocoa - go to foreground/background programmatically