Using User Library for User level changes

Those of you who have been wanting to run a script as the logged in user or manipulate files that are only available in the user's home directory should be able to take advantage of a couple of tricks:

Run as current logged in user:
The current user(s) can be returned using the command: /usr/bin/users

$ /usr/bin/users

So a shell script could be written to perform an action just for them (this one hides the desktop):

/usr/bin/defaults write $PrefDir/com.apple.finder CreateDesktop -bool FALSE
/usr/bin/killall Finder

Also, if you do need to do something to all users, even if they are not logged in, you can do something like this:

for USER_HOME in /Users/*;
  ## Get the short name of each user account (this of course doubles as the users' folder
  USER_ID=`basename "${USER_HOME}"`
  ## For each user account found (except Shared)
  if [ "${USER_ID}" != "Shared" ]; then
/usr/bin/defaults write /Users/$USER_ID/Preferences/com.apple.finder CreateDesktop -bool FALSE
/usr/bin/killall Finder


  • no comments? - MacDude 5 years ago
This post is locked
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ