check which applications enable SMLoginItemSetEnabled

649 Views Asked by At

How to check which applications enabling SMLoginItemSetEnabled?

Terminal or which folder, file contains it?

I run 2 applications below but it can't launch at login => I need check helper app is enabling or not.

http://martiancraft.com/blog/2015/01/login-items/

https://github.com/keith/LoginItemTest

2

There are 2 best solutions below

0
On

Apple didn't recommend use

SMJobCopyDictionary

@discussion The contents of the returned dictionary are NOT wholy representative of the property list on-disk and are not stable from release to release. This routine is deprecated and will be removed in a future release. There will be no provided replacement.

Better use SMCopyAllJobDictionaries method

BOOL enabled = NO;
NSArray *jobs = (NSArray*)SMCopyAllJobDictionaries(kSMDomainUserLaunchd);

if (jobs || [jobs count]>0) {
    for (NSDictionary *job in jobs) {
        if ([[job objectForKey:@"Label"] isEqualToString:bundleId]) {
            ret = [[job objectForKey:@"OnDemand"] boolValue];
            break;
        }
    }
}

[jobs release];
0
On

You can check the login item status using SMJobCopyDictionary(or even SMCopyAllJobDictionaries) like this:

- (BOOL)launchAtLoginWithBundleId:(NSString*)bundleId {
    CFDictionaryRef dict = SMJobCopyDictionary(kSMDomainUserLaunchd, (CFStringRef)bundleId);
    if (dict == NULL) {
        return NO;
    }
    CFRelease(dict);
    return YES;
}