Scripting changing the user picture in macOS

Sometimes, you may want to programmatically set a default user picture (with the option for the user to change it later to a picture of her own choice).

You used to be able to delete the JPEGPhoto attribute and just add in a Picture attribute, but that seems to have broken somewhere between October 2018 and September 2019.

In macOS 10.14.6, if you use dscl to delete the JPEGPhoto attribute, and then add in a Picture attribute, you’ll see one of the user pictures change, but the other one will default to the generic silhouette:

Unfortunately, you also can’t just script writing in the hex of the photo via a dscl . -create /Users/username JPEGPhoto ALLOFTHEHEXTEXT command. You will get a /usr/bin/dscl: Argument list too long error.

Someone on Stack Exchange managed to find a solution using dsimport.

Note: I did some further testing, and you may need to first run

sudo dscl . delete /Users/username JPEGPhoto
sudo dscl . delete /Users/username Picture

before successfully running the script linked to above.

If you run that script, you’ll see it changes both photos.

This script works for now in 10.14.6, and it also works in Catalina beta build 19A578c.


Posted

in

by

Comments

4 responses to “Scripting changing the user picture in macOS”

  1. Rick Avatar
    Rick

    Just for confirmation. What script does this line refer to “before successfully running the script below.”? There is no script below that line. I am assuming the script from the Stack Exchange link.

    1. alanysiu Avatar
      alanysiu

      Thanks for asking, Rick. I’ve changed the wording to be a bit clearer (I believe).

  2. Ilya Avatar
    Ilya

    Thanks for the post, but I’m also confused. Which script are you referring to? I run following commands and still get generic silhouette in Users and Groups:
    sudo dscl . delete /Users/admin JPEGPhoto
    sudo dscl . delete /Users/admin Picture
    sudo dscl . create /Users/admin Picture /Library/User\ Pictures/Fun/Ying-Yang.png
    Tested in 10.14 and 10.15

    1. alanysiu Avatar
      alanysiu

      The Stack Exchange script I linked to above.

Leave a Reply to alanysiu Cancel reply

Your email address will not be published. Required fields are marked *