For Sandboxed apps, to create a launch item, Apple suggest you use LSRegisterURL(..) and SMLoginItemSetEnabled(..) along with a helper tool. I’ve set up everything how I want it but I would like a way (not storing a preference value) to get the status of “if it is registered”. Basically a way to perform the same action as SMLoginItemGetEnabled(...) would.
EDIT: Here is my final code thanks to Rob Keniger’s answer:
- (BOOL)startAtLogin {
NSDictionary *dict = (NSDictionary*)SMJobCopyDictionary(kSMDomainUserLaunchd,
CFSTR("com.yourcompany.app"));
BOOL contains = (dict!=NULL);
[dict release];
return contains;
}
I think you could use
SMCopyAllJobDictionaries(kSMDomainUserLaunchd)to get an array containing dictionaries for all the currently activelaunchdjobs.According to the docs, calling
SMLoginItemSetEnabled()immediately starts the job in question, so if your login task is not in the list returned bySMCopyAllJobDictionaries()then you can probably assume it’s not set to run at login.