Register as Login Item with Cocoa?

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)


Solution 1:

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.


EDIT from the year 2012: Since 2009, when I originally wrote this answer, Growl has switched to LSSharedFileList and I've left the project.

Solution 2:

I stumbled across Ben Clark-Robinson's LaunchAtLoginController. A very elegant solution to a very common problem.