Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically launch an OS X app in minimized mode?

I need to launch my application on startup, but I want it to be "minimized", meaning, it will be opened in the dock but its window won't be displayed.

Same like TeamViewer, if you know this application.

I currently use launchctl with a plist I've added to ~Library\LaunchAgents, and indeed on startup the application is launched, and its window is shown.

How can I launch it in such a hidden / minimized state?

like image 878
Nili Avatar asked Aug 27 '13 10:08

Nili


1 Answers

Uncheck visible at launch in your xib for main application window.

enter image description here

Implement - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag in your app delegate class.

- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
{
    if (!flag) {
        [window makeKeyAndOrderFront:self];
        return YES;
    }
    return NO;
}
like image 63
Parag Bafna Avatar answered Nov 15 '22 05:11

Parag Bafna