2

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.

4

I tested the following under 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}'

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 X 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 X 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

You must log in to answer this question.

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