10

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.

15

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.

  • This was exactly what I needed and I've integrated it into my bootstrapping scripts. – cclark Dec 29 '17 at 22:04
  • did you find a way for Catalina? – Ciprian Tomoiagă Jun 22 '20 at 13:06
  • @Ciprian Tomoiagă, As of Nov 26, 19, when I added the note "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 have not tested since then and the last version I tested it on was 10.15.1. – user3439894 Jun 22 '20 at 13:19
  • Thank you ! I thought maybe you had found a workaround :D – Ciprian Tomoiagă Jun 22 '20 at 13:20
0

On Catalina & beyond the path to Applications has changed, so, adding Login Items might require using something like "/System/Applications/Awesome App.app"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .