When a Mac is set up via ADE and the user account is provisioned via Jamf the user account image is assigned randomly from the images at /Library/User Pictures/
To change the image a user would usually open System Preferences > Users & Groups and click Edit and select an image but what if Users and Groups is restricted how can a user change the image?
The answer I’ve come up although limited is simple script in Jamf with a Policy available in Self Service that is very easy to implement and duplicate.
The Script
#!/bin/bash
# image name in the /Library/User Pictures/Nature/
# Can be Cactus.tif Earth.png Leaf.tif Lightning.tif Nest.tif Sandollar.tif Snowflake.tif Zen.tif
imagename=$4
# Get userid
userid=$(defaults read /Library/Preferences/com.apple.loginwindow lastUserName)
# Delete image
dscl . delete /Users/$userid JPEGPhoto
# Set Image to /Nature/Earth.tif
dscl . create /Users/$userid Picture "/Library/User Pictures/Nature/$imagename"
Let’s go through the script…First we set a Jamf Script Parameter Variable for $4 and use this in the script for the image name. This lets us add the image name in the Policy Script Parameter Value setting so we can easily duplicate our policy and add in the image name.
The script needs the user ID so we change the picture of the logged in user and that is made a variable and added to the dscl commands to first delete the current image and then set the selected image. Note in this example we are using images in the /Nature directory. You can obviously change this to Sport or Fun etc.
The /Nature images are:
Cactus.tif
Earth.png
Leaf.tif
Lightning.tif
Nest.tif
Sandollar.tif
Snowflake.tif
Zen.tif
Add instructions in the Options section for our $4 Parameter as below so it’s easy to select one of these.
Save the script.
So now we have the script sorted. Create a new Policy and add the Script payload to the Policy. Set is as an ongoing Policy and give it a relevant name like Change User Image to Earth.
Now set the Parameter Variable to one of the image names stated we will use Earth.png
You can see here our $4 Parameter Variable Label we set in the Options section of the Script to help us out on the image names we can select.
Create the Policy as a Self Service item and add a description and an icon that is the same as the image, I’ve also changed the button name to Change.
Scope the policy and you are done.
Open up Self Service find your new like Change User Image to Earth item and click the Change button.
After a few seconds the policy is done. To check the image is updated Lock the screen, or close the lid and there you go the image is now the Earth.png close the lid and there you go the image is now the Earth.png
If you want to add Cactus, Leaf etc just duplicate the Policy change the Policy name to the image name, change in Self Service section as well and update the description and icon image and most importantly change the Parameter Script Values to Leaf.tif
Save and refresh Self Service and now you have Earth and Leaf items. Just repeat this for as many images in the Nature folder as you want.
You could of course add a policy that installs an image of your own and reference in your script just drop in in the same place or change the Script path.
If you have a better way that would also allow camera and Memoji, Emoji and Photos then please post a comment or contact me on Slack MacAdmins @cube