Scripting changing user icons: dsimport prompts for password in zsh

2 June, 2021 Update

Special shoutout to Armin Briegel for pointing out that the zsh version runs just fine if you use a different variable name from USERNAME.

I’ve tried it with USERACCOUNT instead, and I’ve confirmed it works fine with zsh.

Original Post

Apple is moving toward making zsh the default shell instead of bash, and it may even eventually remove bash completely from being preinstalled on macOS.

So lots of Mac admins are working to revise scripts from bash to zsh.

Last year, I blogged about Scripting changing the user picture in macOS and referenced this script in particular, which works wonders… that is, unless you try to switch it to zsh.

If you run it as is (using bash), it changes the user picture just fine:

dscl . delete /Users/username JPEGPhoto
dscl . delete /Users/username Picture
userpic.sh username /Library/User\ Pictures/Animals/Zebra.tif

Successfully imported users picture.

If you switch it to zsh, though, it gets permission is denied and then prompts for the password of the user whose picture you’re trying to change:

dscl . delete /Users/username JPEGPhoto
dscl . delete /Users/username Picture
userpic.sh username /Library/User\ Pictures/Animals/Zebra.tif

/usr/local/bin/userpic.sh:16: permission denied: /Library/Caches/username.picture.dsimport
username's password:


Posted

in

by

Tags:

Comments

Leave a Reply

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