• 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: Adding your app to the Login Items?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding your app to the Login Items?


  • Subject: Re: Adding your app to the Login Items?
  • From: Christian Weykopf <email@hidden>
  • Date: Wed, 26 Feb 2003 16:41:30 +0100

Am Dienstag, 25.02.03, um 22:13 Uhr (Europe/Berlin) schrieb Jesus De Meyer:

Is there a way to programmatically add your app to the Login Items without having to modify the loginwindow.plist file yourself?

Try this. The item is in arg[1]

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSMutableArray *loginItems;
NSMutableDictionary *loginDict;
NSString *itemPfad;
int i;

// Apparently, the CFPreference API returns an empty array if host is set to kCFPreferencesAnyHost instead of kCFPreferencesCurrentHost.
// When accessing the array through "[defaults objectForKey:@"AutoLaunchedApplicationDictionary"]", host is very likely set to "kCFPreferencesAnyHost" by Cocoa, therefore the incorrect (?) empty array.

// Ist ein Pfad |bergeben?
if (argc < 2)
return 1;

itemPfad = [NSString stringWithCString: argv[1]];

// Pfad da?
if (!itemPfad)
return 2;

loginItems = (NSMutableArray*) CFPreferencesCopyValue((CFStringRef)@"AutoLaunchedApplicationDictionary" , (CFStringRef) @"loginwindow", kCFPreferencesCurrentUser, kCFPreferencesAnyHost);

loginItems = [[loginItems autorelease] mutableCopy];

for (i = 0; i < [loginItems count]; i++)
{
loginDict = [loginItems objectAtIndex: i];
if (NSOrderedSame == [(NSString *)[loginDict objectForKey:@"Path"] compare: itemPfad])
{
// Ist schon drin
[loginDict release];
[loginItems release];
return 0;
}
}

loginDict = [[NSMutableDictionary alloc] init];

[loginDict setObject: itemPfad forKey: @"Path"];
[loginDict setObject: [NSNumber numberWithBool:FALSE] forKey: @"Hide"];

[loginItems addObject: loginDict];
[loginDict release];
//Do you stuff on "loginItems" array here

CFPreferencesSetValue((CFStringRef)@"AutoLaunchedApplicationDictionary", loginItems, (CFStringRef)@"loginwindow", kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
CFPreferencesSynchronize((CFStringRef) @"loginwindow", kCFPreferencesCurrentUser, kCFPreferencesAnyHost);

[loginItems release];

[pool release];
return 0;
}


_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


--
Christian Weykopf
Meilenstein Mac OS Software

Neue Strasse 5
D-31582 Nienburg
Fax: +49 (0) 5021 91 24 45
<http://www.meilenstein.de/>
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Adding your app to the Login Items? (From: Jesus De Meyer <email@hidden>)

  • Prev by Date: Re: How to get image real number of bits per pixel
  • Next by Date: Re: system.preferences Authorization
  • Previous by thread: Re: Adding your app to the Login Items?
  • Next by thread: Adding your app to the Login Items?
  • Index(es):
    • Date
    • Thread