carpeaqua

March 1

Permalink

Adding an application to Login Items in Mac OS X Leopard

Something that’s always been a bit of a hack in Mac OS X Leopard is settings your application to launch at login per a user preference. Prior to Leopard it involved open the user’s loginwindow.plist file and manually adding/removing it from there or using [Apple’s System Events sample.

Luckily with Leopard, Apple has offered a better way of doing this.

The Shared File List API is new to Launch Services in Mac OS X Leopard. This API provides access to several kinds of system-global and per-user persistent lists of file system objects, such as recent documents and applications, favorites, and login items. For details, see the new interface file LSSharedFileList.h. - Launch Services Release Notes

If you take a peak in the LSSharedFileList.h file, you’ll see all you need to get started. I couldn’t find any sample code on how to use this new functionality, so in an attempt to appease the Google gods and hopefully contribute something useful back to the community, I put together a sample project that adds an application to the currently logged in account’s Login Items listing.

The code looks for the application in the user’s /Applications directory and then adds or removes it based on the user’s preference.

You can grab the sample project at my new public code repository.

http://secondgear-public.googlecode.com/svn/trunk/SGLaunchAtLogin/

If you have any feedback, please send me an email.

carpeaqua is written by Justin Williams. Justin Williams is the crew chief of Second Gear, the creator of such fine Mac applications as Today and Check Off. He currently resides in southern Indiana.

You can learn more about him, send him an or browse the archives

.