I am developing an application that I want to start automatically when the user logs in. There are several answers on how to do this, in particular I'm using the code from this GitHub repository, and it works fine.
What I want now, and couldn't find how to do it, is start the application but without showing the main window. This is only when the application starts on login, if the application is closed and the user opens it with a click in the Dock (or whatever), I want it to show the window.
Is it possible? Any ideas on how to do this?
In the Accounts system preference, where you set the applications that launch on login, there is a "hide" check that does what I want, but I want to do it programmatically.
With the app open control-click on the apps icon in the Dock, select Options and you should see a second sub menu where you can assign which Display to use for that app.
To stop using the app full screen, move the pointer to the green button again, then choose Exit Full Screen from the menu that appears or click the button .
Well, I've found how to do it... This Open Radar bug report helped, I was using the wrong property.
Here's the code:
- (void)enableLoginItemWithLoginItemsReference:(LSSharedFileListRef )theLoginItemsRefs ForPath:(NSString *)appPath {
// We call LSSharedFileListInsertItemURL to insert the item at the bottom of Login Items list.
CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:appPath];
CFMutableDictionaryRef inPropertiesToSet = CFDictionaryCreateMutable(NULL, 1, NULL, NULL);
CFDictionaryAddValue(inPropertiesToSet, kLSSharedFileListLoginItemHidden, kCFBooleanTrue);
LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(theLoginItemsRefs, kLSSharedFileListItemLast, NULL, NULL, url, inPropertiesToSet, NULL);
if (item) {
CFRelease(item);
}
}
The solution was to create a dictionary with the key kLSSharedFileListLoginItemHidden and value true, and pass it to the LSSharedFileListInsertItemURL function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With