How to close NSWindow and remove the application icon from the dock menu

If you are using DropBox on a MacBook, you should have seen this as soon as we finish the registration process. It closes the main window application and removes it from the dock, but the application starts from the status menu.


Visual:

enter image description here


What i have done so far:

  • My application works fine with show NSWindow
  • When I log in from the window of my external application, I can create a status menu icon with a popover
  • At this point, I want to remove the NSWindow and Dock icon, but the application should be accessible from the status menu.

How to achieve this?

FYI: I do not expect any code, just an understanding or a quick hint. I'll find out the rest :)


Resource I mean

Later I will configure my application for launchd . Thus, when the system starts, it can start and display it in the status menu. Now I am looking at a good resource (of course, this is good because its Apple Doc), but since I am a naive programmer, does anyone have a good example of a link? which shows how to add an application in running?

EDIT:

I will follow this tutorial to add to autorun, later the user can change their settings, if they want, they can choose the rotation in my application or turn it off at startup

+6
source share
3 answers

As Tick said, you want the "Application is an agent (UIElement)" key in your info.plist. This key means that you will not have a dock icon ... this is what you want. However, there is no need to use the "Application only for background" key. This key does not allow placing any windows on the screen, which is not necessary. Therefore, I would leave this key.

In general, configure the application so that the window does not automatically appear at startup. Do some startup testing to see if a configuration is needed. If so, make the configuration window visible. You can even have the โ€œConfiguration ...โ€ menu item in your status menu so that your user can open the configuration window at any time. It is really very simple, but just do not use the info.plist "Application only" key.

By the way, itโ€™s a little difficult to make a window to the front. The trick is to make your application first in front, like this ...

[NSApp activateIgnoringOtherApps:YES]; [someWindow makeKeyAndOrderFront:nil]; 
+2
source

To start the application only as a status, 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 them, I'm not sure what the best way is, but I would suggest making the setup process my own application. (Application with icon and window). You would have to contain the application in your application menu and automatically launch it when the user starts the program ...

+4
source

Usually, the situation mentioned in the example with Dropbox is solved using two separate applications: one for the menu and the other for the other part of ui (which has the mentioned dock icon fe), and two processes interact via fe IPC.

doing the same thing in one application is a little difficult, you can find my details about it here

Cocoa - programmatic transition to the foreground / background

0
source

Source: https://habr.com/ru/post/917140/


All Articles