Hi all,
How can an application determine if it was launched as a Startup Item
on logging in to Mac OS or a usual way like (double)clicking it's
icon?
please provide me guidance for this.
i m check this sample code to detect the app launch from Login Items or Not.
but its not working.
thanks in advance.
How can an application determine if it was launched as a Startup Item
on logging in to Mac OS or a usual way like (double)clicking it's
icon?
please provide me guidance for this.
i m check this sample code to detect the app launch from Login Items or Not.
Code:
+ (BOOL)wasLaunchedAsLoginItem
{
// If the launching process was 'loginwindow', we were launched as a
login item
return [self wasLaunchedByProcess:@"lgnw"];
}
+ (BOOL)wasLaunchedByProcess:(NSString*)creator
{
BOOL wasLaunchedByProcess = NO;
// Get our PSN
OSStatus err;
ProcessSerialNumber currPSN;
err = GetCurrentProcess (&currPSN);
if (!err) {
// Get information about our process
NSDictionary* currDict = (NSDictionary*)
ProcessInformationCopyDictionary (&currPSN,
kProcessDictionaryIncludeAllInformationMask);
// Get the PSN of the app that *launched* us. Its not really the
parent app, in the unix sense.
long long temp = [[currDict objectForKey:@"ParentPSN"] longLongValue];
[currDict release];
long long hi = (temp >> 32) & 0x00000000FFFFFFFFLL;
long long lo = (temp >> 0) & 0x00000000FFFFFFFFLL;
ProcessSerialNumber parentPSN = {(unsigned long)hi, (unsigned long)lo};
// Get info on the launching process
NSDictionary* parentDict = (NSDictionary*)
ProcessInformationCopyDictionary (&parentPSN,
kProcessDictionaryIncludeAllInformationMask);
// Test the creator code of the launching app
wasLaunchedByProcess = [[parentDict objectForKey:@"FileCreator"]
isEqualToString:creator];
[parentDict release];
}
return wasLaunchedByProcess;
}
but its not working.
thanks in advance.
Last edited by a moderator: