How to programmatically launch an OSX application in minimized mode?

I need to run the application at startup, but I want it to be "minimized", that is, it will be open in the dock, but its window will not be displayed.

Same as TeamViewer if you know this application.

I am currently using launchctll with plist, which I added to the \ LaunchAgents library, and even when I launch the application starts up and its window is displayed.

How can I run it in such a "hidden" "minimized" state?

+4
source share
3 answers

Uncheck the box at startup in your xib for the main application window.

enter image description here

Paste - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag in the application delegate class.

 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag { if (!flag) { [window makeKeyAndOrderFront:self]; return YES; } return NO; } 
+5
source

The next line will help you achieve

[[self window] miniaturize: self];

0
source

minimized .. I think you want to run it as HIDDEN

see NSWorkspace:

- (BOOL)launchAppWithBundleIdentifier:(NSString *)bundleIdentifier options:(NSWorkspaceLaunchOptions)options additionalEventParamDescriptor:(NSAppleEventDescriptor *)descriptor launchIdentifier:(NSNumber **)identifier

use this to launch an application from another application and pass the NSWorkspaceLaunchAndHide option


if you are interested in how you get the application, so as not to show the dock icon:

define LSUIElement = YES in your plist

0
source

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


All Articles