Adding and removing individual login items from Terminal

Dec 27, '11 07:30:00AM

Contributed by: jollyroger

As shown in this hint, there is a way to use the defaults command-line tool to add items to the Login Items list of the Accounts or Users & Groups System Preference panel:

defaults write loginwindow AutoLaunchedApplicationDictionary -array-add '{ "Path" = "/path/to/itemname"; "Hide" = 0; }'
Unfortunately, Apple provides no easy way to use defaults to remove a given login item from the list. While you can remove all login items by deleting AutoLaunchedApplicationDictionary, that's usually not what you want to do.

Luckily, there's another way to do it that does allow removal of individual items as well as other things.

A nice work-around solution is to instead use the osascript command-line tool to do it with simple AppleScript commands:

Add an item:
osascript -e 'tell application "System Events" to make login item at end with properties {path:"/path/to/itemname", hidden:false}' 
Remove an item:
osascript -e 'tell application "System Events" to delete login item "itemname"' 
List all items:
osascript -e 'tell application "System Events" to get the name of every login item'
Enjoy!

[crarko adds: Note that the easiest way to get the path to the login item 'itemname' may be to open System Preferences » Accounts, click the 'Login Items' tab and then right-click (Ctrl+click) the name of the item. This displays a 'Reveal in Finder' submenu and you can determine the path from that.]

Comments (4)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20111226075701552