login items for user via command line

tranatisoc
New Contributor II

hi -

please could someone help me with a command line or script to find out a user's login items?

and a command line or script to remove an item?

thanks in advanced.

4 REPLIES 4

kerouak
Valued Contributor

You could start here...

sudo defaults delete ~/Library/Preferences/com.apple.loginitems [some key] [somestring]

NoahRJ
Contributor II

More specifically, to grab the list of a user's login items, something like this should work:

CurUser=$(ls -l /dev/console | awk '{print $3}')
defaults read /Users/$CurUser/Library/Preferences/com.apple.loginitems.plist | grep Name

On the other hand, AppleScript run in Terminal looks like it can manipulate/read these values better than defaults (because the values are deeply nested within the plist):

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

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

I pulled those commands from this gist, so give that a once over and see if it works for your needs.

tranatisoc
New Contributor II

thank you both. reading from plist seems to work. the applescript is hit or miss. not sure why

ateazzie
New Contributor III

Hi, thnx for the tip but I get, expected end of line but found unknown token, on MacOS 10.13.5

what am I doing wrong

thnx