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: Tue, 20 Mar 2007 10:26:19 -0400
- Organization: Rogue Research
On 2007-03-19 21:28, Dave MacLachlan said:
>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.
That was my code, and I guess you saw the discussion on carbon-dev:
<http://lists.apple.com/archives/carbon-dev/2007/Mar/msg00274.html>
Your fix below is no good, because as you say it is a bug in 10.4.x and
is fixed in 10.5. The best way is to not use
ProcessInformationCopyDictionary() if you intend to look at the "PSN" or
"Parent PSN" values. Instead, use the older GetProcessInformation().
When I get home (where my shareware code is) I can repost the whole
working snippit for the archives.
Sean
>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
>
_______________________________________________
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