Mac OS X: open application at login, without showing the main window

后端 未结 1 1564
借酒劲吻你
借酒劲吻你 2021-01-01 01:13

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

相关标签:
1条回答
  • 2021-01-01 02:08

    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.

    0 讨论(0)
提交回复
热议问题