FROM : Sean McBride
DATE : Sat Dec 11 18:45:25 2004
Mark Munz (<email_removed>) 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_removed>
Mac Software Designer Montréal, Québec, Canada
DATE : Sat Dec 11 18:45:25 2004
Mark Munz (<email_removed>) 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_removed>
Mac Software Designer Montréal, Québec, Canada
| Related mails | Author | Date |
|---|---|---|
| Mihkel Tammepuuu | Dec 4, 09:20 | |
| M. Uli Kusterer | Dec 4, 09:28 | |
| Finlay Dobbie | Dec 4, 19:15 | |
| Mihkel Tammepuuu | Dec 4, 20:16 | |
| Darkshadow | Dec 5, 07:03 | |
| Mark Munz | Dec 5, 19:19 | |
| Sean McBride | Dec 11, 18:45 |






Cocoa mail archive

