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
macdude
So a shell script could be written to perform an action just for them (this one hides the desktop):
#!/bin/bash
CurUser=`/usr/bin/users`
PrefDir=/Users/$CurUser/Library/Preferences
/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/*;
do
## 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
fi
/usr/bin/killall Finder
done
Comments