Can Login Items be added via a command in terminal?
I would like to add a few essential utilities like ShiftIt and Alfred to my Login Items via a script when I'm configuring a new Mac. In versions of macOS previous to High Sierra these items were stored in a plist in ~/Library/Preferences/com.apple.loginitems.plist
but since High Sierra has been released it seems they've been migrated to be loaded via a new mechanism.
I am interested in ways to set Login Items from a terminal primarily for High Sierra but interested from an academic perspective to know how it could be done in prior releases of macOS.
Best Answer
macOS Catalina Update: While the information in this answer holds true as stated and tested in the versions of OS X/macOS listed below, it does not work in macOS Catalina 10.15.
I tested the following under macOS 10.14.6, macOS 10.13.1 and OS X 10.8.6.
In Terminal, using the following syntax:
\
) when it is in quotes.Tested with an application named EventScripts:
It returned:
Which is apparently the normal output with this command and was verified by preforming the same action in Script Editor.
Then looking in System Preferences > Users & Groups > $USER > Login Items, EventScripts was added.
Notes:
In OS X 10.8.6 it updated the following file:
In macOS 10.13.1[1] it updated the following file:
Which, by the way, is also a plist file, but with a btm extension.
You can also delete a Login Item from Terminal using the following syntax:
Where
"name"
in the command is as show in the output of the following command:[1] Update: The
backgrounditems.btm
file is still the target file since macOS 10.13.1 and later.