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
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.