tags:

views:

1289

answers:

3

Google gave me: http://developer.apple.com/samplecode/LoginItemsAE/index.html

And I figured there must be a better way than using AppleScript Events.

So I downloaded the Growl sources. They use the exact sources from that Apple developer article.

Is there a better way?

(I refer to Login Items in Accounts in System Preferences, ie. making my program start when the user Logs in, programmatically)

A: 

I can't remember of the top of my head but aren't the login items stored in a plist file in the user's Library? So it would be just a matter of adding your application using the default command (for example during installation?)

hhafez
That's private storage of {System Events,LSSharedItemList}. The layout within the property list has changed at least once (for the introduction of LSSharedItemList), so I wouldn't recommend relying on that layout in the future.
Peter Hosey
+4  A: 

I do this in an app I'm writing:

Check out UKLoginItemRegistry for an easy way to do this pragmatically. Afaik, there is no way in Tiger to do this without Apple Events; in Leopard there's a better way, but if you use UKLoginItemRegistry it really is no problem. Here's the complete code for implementing an "Open at Logon" menu item

+ (bool)isAppSetToRunAtLogon {
  int ret = [UKLoginItemRegistry indexForLoginItemWithPath:[[NSBundle mainBundle] bundlePath]];
  NSLog(@"login item index = %i", ret);
  return (ret >= 0);
}

- (IBAction)toggleOpenAtLogon:(id)sender {
  if ([PopupController isAppSetToRunAtLogon]) {
    [UKLoginItemRegistry removeLoginItemWithPath:[[NSBundle mainBundle] bundlePath]];
  } else {
    [UKLoginItemRegistry addLoginItemWithPath:[[NSBundle mainBundle] bundlePath] hideIt: NO];
  }
}
Paul Betts
Does the code realize if it doesn't have to use AppleScript?
Alexsander Akers
Code doesn't realize anything, it's just some bits on a disk. I don't understand what you're saying.
Paul Betts
+9  A: 

There's an API that's new in Leopard called LSSharedFileList. One of the things it lets you do is view and edit the Login Items list (called Session Login Items in that API).

BTW, I'm the lead developer of Growl. We haven't switched away from AE yet because we still require Tiger, but I'm thinking of dropping that for 1.2 (haven't talked it over with the other developers yet). When we do drop Tiger, we'll drop LoginItemsAE as well, and switch to the Shared File List API.

Peter Hosey
I think you mean LSSharedFileList
Nathan Kinsinger