Re: Background if Login Item launched
Re: Background if Login Item launched
- Subject: Re: Background if Login Item launched
- From: "Sean McBride" <email@hidden>
- Date: Sat, 15 Oct 2005 14:42:09 -0400
Bill Patterson (email@hidden) on 2005-09-29 15:02 said:
>I have an application that normally is launched as a Login Item, but
>the first time, it is launched by the user. I need to detect which
>method is used, and suppress the application from becoming the active
>application if launched as a Login Item.
>
>How can I detect if the application is launched via the Login Items?
Sorry for the extremely delayed reply, but here is some code answering
your question. Basically, you want to test if the parent app was loginwindow:
+ (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;
}
--
____________________________________________________________
Sean McBride, B. Eng email@hidden
Mac Software Designer Montréal, Québec, Canada
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden