• 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: Background if Login Item launched
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Background if Login Item launched


  • Subject: Re: Background if Login Item launched
  • From: Dave MacLachlan <email@hidden>
  • Date: Mon, 19 Mar 2007 21:28:12 -0700

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


  • Follow-Ups:
    • Re: Background if Login Item launched
      • From: "Sean McBride" <email@hidden>
    • Re: Background if Login Item launched
      • From: Dave MacLachlan <email@hidden>
  • Prev by Date: Getting the last date of the month?
  • Next by Date: Re: Image manipulation on 10.3
  • Previous by thread: [SOLVED] Re: Getting the last date of the month?
  • Next by thread: Re: Background if Login Item launched
  • Index(es):
    • Date
    • Thread