Apple - Can Login Items be added via the command line in High Sierra?

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:

osascript -e 'tell application "System Events" to make login item at end with properties {path:"/path/to/itemname", hidden:false}'
  • Note: If there are spaces in a path filename, do not escape the spaces with a backslash (\) when it is in quotes.

Tested with an application named EventScripts:

osascript -e 'tell application "System Events" to make login item at end with properties {path:"/Applications/EventScripts.app", hidden:false}'

It returned:

login item UNKNOWN

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:

~/Library/Preferences/com.apple.loginitems.plist

In macOS 10.13.1[1] it updated the following file:

~/Library/Application Support/com.apple.backgroundtaskmanagementagent/backgrounditems.btm

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:

osascript -e 'tell application "System Events" to delete login item "name"'

Where "name" in the command is as show in the output of the following command:

osascript -e 'tell application "System Events" to get the name of every login item'

[1] Update: The backgrounditems.btm file is still the target file since macOS 10.13.1 and later.