This is simple but handy command to add LoginItems (items that are executed after the user logs in) via the command line using the default tool. To add a normal startup item, use this syntax:
[robg adds: Caution: If you form this command incorrectly, it's possible you could overwrite all of your login items -- backup the loginwindow.plist file before starting -- it's in your user's Library/Preferences folder. There's no similar easy way to remove an added item via the command line, since it's part of an array of values. You could just use pico or vi on the loginwindow.plist file, of course ... or once you have the GUI available, via the normal Login Items tab in the Accounts pane of System Preferences.]
defaults write loginwindow AutoLaunchedApplicationDictionary -array-add \
'<dict><key>Hide</key><false/><key>Path</key><string>/path/to/item</string></dict>'
Of course, replace /path/to/item with the absolute path to whatever it is you want to open. Also, if you want the opened thing to hide itself when it opens, just change the word false, after the Hide key, to true. That's all there is to it.
[robg adds: Caution: If you form this command incorrectly, it's possible you could overwrite all of your login items -- backup the loginwindow.plist file before starting -- it's in your user's Library/Preferences folder. There's no similar easy way to remove an added item via the command line, since it's part of an array of values. You could just use pico or vi on the loginwindow.plist file, of course ... or once you have the GUI available, via the normal Login Items tab in the Accounts pane of System Preferences.]
•
[21,461 views]

