CocoaDev

Edit AllPages

To know if your application was launched because it is a login item, as opposed to being launched explicitly by the user from the Finder, use the code below:

or, you may determine this through an Apple Event:

(void) handleOpenApplicationEvent: (NSAppleEventDescriptor ) event replyEvent: (NSAppleEventDescriptor *) replyEvent { NSAppleEventDescriptor propData = [event paramDescriptorForKeyword: keyAEPropData]; bool startAtLogin = false; DescType type = propData ? [propData descriptorType] : typeNull; OSType value = 0;

if(type == typeType)
{
    value = [propData typeCodeValue];
    startAtLogin = (value == 'lgit'); //keyAELaunchedAsLogInItem
}

NSLog(@"PropDataTypeValue:%i startAtLogin:%i", value, startAtLogin ); }

If you wish to determine if an application is amongst the user’s current login items:

These are two different tests, since an app can be a login item but still be launched from the Finder.

If you want to add an application to the set of login items, see StartingMyAppOnStartup.