Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Starting as Startup Item?



Mark Munz (email@hidden) on Sun, Dec 5, 2004 1:19 PM said:

>> You can check the loginwindow.plist file, and see if your application
>> is listed there.  This code should do it.  Note that the autolaunched
>
>I don't know the reason you need to know the difference between
>starting up as a login or not, but be careful, because this solution
>will only "mostly" work.

(Sorry for my late reply, I am 700 messages behind. :()


I have found a reliable way to make the distinction, through
experimentation.  This works for me, but I don't think its officially
documented, nor does there seem to be any official way, so....


+ (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 = (NSDiction
ary*)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];
		ProcessSerialNumber	parentPSN = {(temp >> 32) & 0x00000000FFFFFFFFLL,
(temp >> 0) & 0x00000000FFFFFFFFLL};

		// Get info on the launching process
		NSDictionary*	parentDict = (NSDicti
onary*)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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >Re: Starting as Startup Item? (From: Mark Munz <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.