Skip to content

Instantly share code, notes, and snippets.

@scriptingosx
Created October 23, 2018 07:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scriptingosx/2bc337d3a7f6c81fcb869d71ce3619ca to your computer and use it in GitHub Desktop.
Save scriptingosx/2bc337d3a7f6c81fcb869d71ce3619ca to your computer and use it in GitHub Desktop.
sample script that loops through all users and sets a different user picture.
#!/bin/bash
# create an array from all images in the User Pictures subfolders
IFS=$'\n' read -rd '' -a pictures <<< "$(find '/Library/User Pictures/Fun' -name *.tif -print )"
# loop through all users
picIndex=0
userList=$(dscl . list /Users UniqueID | awk '$2 > 500 {print $1}')
for user in $userList; do
echo "$user"
# delete JPEGPhoto
dscl . delete "/Users/$user" JPEGPhoto
# update path in picture
echo ${pictures[$picindex]}
dscl . create "/Users/$user" Picture "${pictures[$picindex]}"
((picindex++))
if [[ $picindex -eq ${#pictures[@]} ]]; then
picindex=0
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment