• 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: Agent Applications and launchd
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Agent Applications and launchd


  • Subject: Re: Agent Applications and launchd
  • From: Joachim <email@hidden>
  • Date: Wed, 28 Dec 2005 11:56:48 -0800

Keith Alperin wrote:
The consensus right now seems to be that I should use a login item.
I'll post again after I try that and include the code that I use.

Keith, I'm currently coding this functionality too, and based on the sample code on http://www.cocoabuilder.com/archive/message/cocoa/ 2002/7/3/54254, I've successfully installed and unstalled my login item on Tiger with the following piece of code:

- (void)registerLoginItem:(BOOL)flag
{
NSMutableArray *loginItems;
NSDictionary *appDict;
NSEnumerator *appEnum;
NSString *agentAppPath = [self agentPath]; // absolute path to .app

// Make a mutable copy (why a copy?)
loginItems = (NSMutableArray*) CFPreferencesCopyValue ((CFStringRef)
@"AutoLaunchedApplicationDictionary", (CFStringRef) @"loginwindow",
kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
loginItems = [[loginItems autorelease] mutableCopy];

// Check if we're already registered (appDict will be non-nil)
appEnum = [loginItems objectEnumerator];
while (appDict = [appEnum nextObject]) {
if ([[[appDict objectForKey:@"Path"] stringByExpandingTildeInPath]
isEqualToString:agentAppPath]) {
break;
}
}

if (flag) {
// Register the item
if (!appDict) {
NSDictionary *agentDict =
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:NO], @"Hide",
agentAppPath, @"Path", nil];
[loginItems addObject:agentDict];
}
} else if (appDict) {
// Unregister the item
[loginItems removeObject:appDict];
}

// Set the value(s)
CFPreferencesSetValue ((CFStringRef)
@"AutoLaunchedApplicationDictionary", loginItems, (CFStringRef)
@"loginwindow", kCFPreferencesCurrentUser, kCFPreferencesAnyHost);

// Update the preferences dictionary
CFPreferencesSynchronize ((CFStringRef) @"loginwindow",
kCFPreferencesCurrentUser, kCFPreferencesAnyHost);

[loginItems release];
}

Hope it helps,
Joachim
_______________________________________________
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
  • Follow-Ups:
    • Re: Agent Applications and launchd
      • From: Finlay Dobbie <email@hidden>
  • Prev by Date: Re: looking for a cocoa programmer ( paid job )
  • Next by Date: Re: duplicate a file
  • Previous by thread: Re: Agent Applications and launchd
  • Next by thread: Re: Agent Applications and launchd
  • Index(es):
    • Date
    • Thread