Re: Background if Login Item launched
Re: Background if Login Item launched
- Subject: Re: Background if Login Item launched
- From: Dave MacLachlan <email@hidden>
- Date: Mon, 19 Mar 2007 22:24:33 -0700
Looking closer at this, it appears it may be a bug. Can someone with
inside knowledge confirm? It also appears to be fixed in Leopard, so
you may want to code appropriately. I'm not sure what version of 10.4
this broke in (if it ever worked), but it's definitely broken in 10.4.9.
radar: 5074332 ProcessSerialNumbers returned by
ProcessInformationCopyDictionary bad on i386
Cheers,
Dave
On Mar 19, 2007, at 21:28 , Dave MacLachlan wrote:
Sorry to dredge up an ancient thread, but I thought people may
appreciate this. A chunk of oft repeated code needed some repairs.
This code is now byte order dependent on Intel.
Cheers,
Dave
FROM : Sean McBride
DATE : Sat Oct 15 20:42:09 2005
Bill Patterson (<email_removed>) 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?
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;
#if TARGET_RT_BIG_ENDIAN
ProcessSerialNumber parentPSN = {(unsigned long)hi,
(unsigned long)lo};
#else
ProcessSerialNumber parentPSN = {(unsigned long)lo,
(unsigned long)hi};
#endif
// 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;
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden