Login items, continued
Following up on my loginitem script, Nick writes:
I was wondering if this script could be modified to remove all login items from all users and not just the currently logged in one? We have about 30 computers with at least 6 users each that we need to remove all the login items from. Think it would be possible?
It turns out that because loginitem uses AppleScript to ask System Events.app to do the work, it’s fundamentally limited to operating on the current user’s login items. We’ll need some other way of manipulating those settings. Fortunately, this particular problem (deleting all login items) has a convenient solution.
Referring back to Apple’s documentation, we see that a user’s login items are stored in ~/Library/Preferences/loginitem.plist. For a single user, it’s sufficient to delete the AutoLaunchedApplicationDictionary key and log out and in again, but we’re trying to automate this process across a number of users.
Here, finally, is the recipe:
- Create a “pristine” version of loginitem.plist, with no login items in it. You might do this by opening ~/Library/Preferences/loginitem.plist in Property List Editor and deleting the AutoLaunchedApplicationDictionary key, or by running the command:
defaults delete loginwindow \ AutoLaunchedApplicationDictionary - Stash that file somewhere:
cp ~/Library/Preferences/loginitem.plist /tmp/
- Run:
for aHome in /Users/*; do sudo cp /tmp/loginitem.plist \ $aHome/Library/Preferences/ done
[Theoretically it should suffice to simply delete the loginitem.plist file, since the remaining values in that file (BuildVersionStampAsNumber, etc.) seem like the sort of things that the system could re-create for you. I don't know if it does, though, so the safest bet is to preserve them.]
Exercise: Convert your pristine loginitem.plist to text (either with defaults read or plutil); embed in a script; ssh in parallel to all the Macs in your lab, downloading and running the script on each.
About this entry
- Currently reading:
- “Login items, continued”
- Author:
- Daniel Sandler
- Published:
- 10.03.07 / 12pm
- Categories:
- Code Journal