Skip to main content
Question

login items for user via command line

  • June 26, 2017
  • 4 replies
  • 20 views

Forum|alt.badge.img+4

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

Forum|alt.badge.img+13
  • Valued Contributor
  • June 26, 2017

You could start here...

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


Forum|alt.badge.img+14
  • Contributor
  • June 26, 2017

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.


Forum|alt.badge.img+4
  • Author
  • Contributor
  • June 26, 2017

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


Forum|alt.badge.img+4
  • Contributor
  • July 30, 2018

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