Worklet: Setting MacOS Screensaver

Note: This worklet changes the screensaver setting only for the current signed in user. The way this worklet was written creates a folder to save screensaver images to, and clears out that folder each time the worklet is run so you can add in new pictures if needed.

Exit 1


# Get user logged into console and put into variable "user"
user=`ls -l /dev/console | cut -d " " -f 4`

#Creates a /Library/Backgrounds folder if there is not one already
mkdir -p /Library/Backgrounds

# Removes the previously saved screensavers in the background folder
rm -rf /Library/Backgrounds/*

# This is where the new screensavers are referenced, add/remove as necessary
# Each image lasts for 5 seconds, so for a longer time, copy the image a few times
scp screensaver1.png "/Library/Backgrounds/"
scp screensaver2.png "/Library/Backgrounds/"
scp screensaver3.png "/Library/Backgrounds/"
scp screensaver4.png "/Library/Backgrounds/"
scp screensaver5.png "/Library/Backgrounds/"
scp screensaver6.png "/Library/Backgrounds/"
scp screensaver7.png "/Library/Backgrounds/"
scp screensaver8.png "/Library/Backgrounds/"

#This section sets the preferences to use for screen savers. 
sudo -u $user defaults -currentHost write CleanExit -string "YES"
sudo -u $user defaults -currentHost write PrefsVersion -int 100
sudo -u $user defaults -currentHost write showClock -string "NO"
#This idle time is counted as seconds, change the 600 (10 minutes) as needed.
sudo -u $user defaults -currentHost write idleTime -int 600
sudo -u $user defaults -currentHost write moduleDict -dict moduleName -string "iLifeSlideshows" path -string "/System/Library/Frameworks/ScreenSaver.framework/Resources/iLifeSlideshows.saver" type -int 0
sudo -u $user defaults -currentHost write tokenRemovalAction -int 0

sudo -u $user defaults -currentHost write LastViewedPhotoPath -string ""
sudo -u $user defaults -currentHost write SelectedFolderPath -string "/Library/Backgrounds"
sudo -u $user defaults -currentHost write SelectedSource -int 3
sudo -u $user defaults -currentHost write ShufflesPhotos -bool false

sudo -u $user defaults -currentHost write styleKey -string "Classic"

sudo killall -hup cfprefsd

Upload the images you want to use, if you don’t want to use the “screensaver_” naming scheme, be sure to use the correct image names where the new images are referenced.

1 Like

I had some issues with this worklet on our managed Macs. The best writeup I found about an issue with password-protected screensavers and a recent fix can be seen here:

Per their suggestions, I took an element of this worklet (Getting current logged-in user) and then applied a very simple screensaver policy using the default squiggly line screensaver:

# Get user logged into console and put into variable user
user=`ls -l /dev/console | cut -d " " -f 4`
#This section sets the preferences to use for screen savers.
#Integers are counted as seconds, change as needed.  600 is 10 minutes
sudo -u $user defaults -currentHost write askForPassword -bool TRUE
sudo -u $user defaults -currentHost write loginWindowIdleTime -int 600
sudo -u $user defaults -currentHost write askForPasswordDelay -int 1

If there is a better way to do this I’m open to it! But, for now, I can confirm this works on a non-AD managed Macbook running 10.14. I do not expect this to change for versions more recent than 10.14.


Thanks for that, my worklet seemed to work fine up until the 10.14 update.