• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Starting as Startup Item?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Starting as Startup Item?


  • Subject: Re: Starting as Startup Item?
  • From: "Sean McBride" <email@hidden>
  • Date: Sat, 11 Dec 2004 12:45:25 -0500

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:

This email sent to email@hidden

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

  • Prev by Date: Re: Kill other process's warning dialog
  • Next by Date: Re: Localized decimal point?
  • Previous by thread: Re: Starting as Startup Item?
  • Next by thread: Re: Starting as Startup Item?
  • Index(es):
    • Date
    • Thread