OS X: Show Application Agent Interface (UIElement)

How can I make an interface for an application for which the Agent application (UIElement) is installed, installed yes?

The interface appears when you first start the application, but if I close the window and click the application icon, nothing will happen. I assume that this is because OS X is trying to start the application again, and there is a mechanism to prevent this. I would like to:

  • The first click on the application icon should launch the application and show the interface.
  • If the interface was closed (but the application is still running in the background), a subsequent click on the icon should simply show the interface.
  • If the interface is already shown, clicking on the icon should simply move the window to the foreground.
+4
source share
2 answers

I found the answer here: Closing a Mac application (clicking the red cross on top) and reopening it by clicking on the dock icon .

- (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication hasVisibleWindows:(BOOL)flag { [self.window makeKeyAndOrderFront:self]; return YES; } 
+2
source

Here's how you can do it:

1) add the + initialize method to your application delegate

 + (void)initialize { // check if there is a running instance of your app NSArray * apps = [NSRunningApplication runningApplicationsWithBundleIdentifier:[[NSBundle mainBundle] bundleIdentifier]]; if ([apps count] > 1) { //post notification to it to update inteface [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"updateInterface" object:nil]; //quit current instance of the app, coz you don't need two apps running continiously exit(0); } } 

2) Register the application for notification

 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(updateInterface:) name:@"updateInterface" object:nil]; } 

3) Add updateInterface method

 - (void)updateInterface:(NSNotification *)aNotification { // handle your interface here // .... // move your app forward [NSApp activateIgnoringOtherApps:YES]; } 
+2
source

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


All Articles