Catalina - screensaver

jameson
Contributor II

Anyone able to set screensavers on Catalina. I had below script that worked fine for Mojave - but for Catalina it does not

#!/bin/sh
# Get user logged into console and put into variable "user"
user=`ls -l /dev/console | cut -d " " -f 4`
osMajor=$(sw_vers -productVersion | awk -F"." '{print $2}')
osMinor=$(sw_vers -productVersion | awk -F"." '{print $3}')


sudo -u $user defaults -currentHost write com.apple.screensaver CleanExit -string "YES"
sudo -u $user defaults -currentHost write com.apple.screensaver PrefsVersion -int 100
sudo -u $user defaults -currentHost write com.apple.screensaver showClock -string "NO"
sudo -u $user defaults -currentHost write com.apple.screensaver idleTime -int 120


if [[ $osMajor -eq 14 ]] && [[ $osMinor -ge 2 ]]; then

        sudo -u $user defaults -currentHost write com.apple.screensaver moduleDict -dict moduleName -string "iLifeSlideshows" path -string "/System/Library/Frameworks/ScreenSaver.framework/PlugIns/iLifeSlideshows.appex" type -int 0

        else

        sudo -u $user defaults -currentHost write com.apple.screensaver moduleDict -dict moduleName -string "iLifeSlideshows" path -string "/System/Library/Frameworks/ScreenSaver.framework/Resources/iLifeSlideshows.saver" type -int 0
fi


sudo -u $user defaults -currentHost write com.apple.screensaver tokenRemovalAction -int 0

sudo -u $user defaults -currentHost write com.apple.ScreenSaverPhotoChooser LastViewedPhotoPath -string ""
sudo -u $user defaults -currentHost write com.apple.ScreenSaverPhotoChooser SelectedFolderPath -string "/Library/EC/lockscreens"
sudo -u $user defaults -currentHost write com.apple.ScreenSaverPhotoChooser SelectedSource -int 3

sudo -u $user defaults -currentHost write com.apple.ScreenSaver.iLifeSlideShows styleKey -string "Classic"

sudo killall -hup cfprefsd
10 REPLIES 10

JCMBowman
New Contributor III

Try this instead - note that I changed the actual screen saver and the photo path being applied to suit my uses...

#!/bin/zsh
# Get user logged into console and put into variable "user"
user=`ls -l /dev/console | cut -d " " -f 4`
osMajor=$(sw_vers -productVersion | awk -F"." '{print $2}')
osMinor=$(sw_vers -productVersion | awk -F"." '{print $3}')


sudo -u $user defaults -currentHost write com.apple.screensaver CleanExit -string "YES"
sudo -u $user defaults -currentHost write com.apple.screensaver PrefsVersion -int 100
sudo -u $user defaults -currentHost write com.apple.screensaver showClock -string "NO"
sudo -u $user defaults -currentHost write com.apple.screensaver idleTime -int 120


if [[ $osMajor -eq 14  && $osMinor -ge 2 ]] || [[ $osMajor -ge 15 ]] ; then

        sudo -u $user defaults -currentHost write com.apple.screensaver moduleDict -dict moduleName -string "iLifeSlideshows" path -string "/System/Library/Frameworks/ScreenSaver.framework/PlugIns/iLifeSlideshows.appex" type -int 0

        else

        sudo -u $user defaults -currentHost write com.apple.screensaver moduleDict -dict moduleName -string "iLifeSlideshows" path -string "/System/Library/Frameworks/ScreenSaver.framework/Resources/iLifeSlideshows.saver" type -int 0
fi


sudo -u $user defaults -currentHost write com.apple.screensaver tokenRemovalAction -int 0

sudo -u $user defaults -currentHost write com.apple.ScreenSaverPhotoChooser LastViewedPhotoPath -string ""
sudo -u $user defaults -currentHost write com.apple.ScreenSaverPhotoChooser SelectedFolderPath -string "/Library/Screen Savers/Default Collections/MyPics"
sudo -u $user defaults -currentHost write com.apple.ScreenSaverPhotoChooser SelectedSource -int 3

sudo -u $user defaults -currentHost write com.apple.ScreenSaver.iLifeSlideShows styleKey -string "VintagePrints"

killall -hup cfprefsd

The issue in the old script was that the "if" statement was looking for anything that was a major OS version equal to 14, and had a minor OS version greater than or equal to 1. But that meant that under catalina it didn't meet the major OS version so it applied the 10.14.1 and earlier fix.

Lives
New Contributor II

@JCMBowman Thank you, this worked nicely!
Does anyone know what I would have to change in order to uncheck Shuffle Slide Order off?

Thanks!

JCMBowman
New Contributor III

@Lives - try adding this line near the similar lines for com.apple.ScreenSaverPhotoChooser:

sudo -u $user defaults -currentHost write com.apple.ScreenSaverPhotoChooser ShufflesPhotos -bool FALSE

sfaeder
New Contributor III

I tried using this script and it does not seem to work for me at all on any MacOS version. No matter what I do, it only shows the stock photos. I verified the folder path is correct. Is there something else that needs to be changed aside from the SelectedFolderPath? Hopefully I'm just missing something small!

smpotter
New Contributor III

I'm using this to set custom screensavers across all our Mac (macOS 10.13.x - 10.15.7 ) and it works great. I have custom folder created at "/Library/Screen Savers/Default Collections/CompanyName" where I place the image files and then execute the script (postinstall)...

#!/bin/sh

## get current user
user=`ls -l /dev/console | cut -d " " -f 4`

## get macOS version(s)
osMajor=$(/usr/bin/sw_vers -productVersion | /usr/bin/awk -F"." '{print $2}')
osMinor=$(/usr/bin/sw_vers -productVersion | /usr/bin/awk -F"." '{print $3}')

## set key items for screensaver
/usr/bin/sudo -u $user /usr/bin/defaults -currentHost write com.apple.screensaver CleanExit -string "YES"
/usr/bin/sudo -u $user /usr/bin/defaults -currentHost write com.apple.screensaver PrefsVersion -int 100
/usr/bin/sudo -u $user /usr/bin/defaults -currentHost write com.apple.screensaver showClock -string "NO"
/usr/bin/sudo -u $user /usr/bin/defaults -currentHost write com.apple.screensaver idleTime -int 1200

## configure screensaver framework based on macOS version
if [[ $osMajor -eq 14 ]] && [[ $osMinor -ge 2 ]]; then
    /usr/bin/sudo -u $user /usr/bin/defaults -currentHost write com.apple.screensaver moduleDict -dict moduleName -string "iLifeSlideshows" path -string "/System/Library/Frameworks/ScreenSaver.framework/PlugIns/iLifeSlideshows.appex" type -int 0
  else
    /usr/bin/sudo -u $user /usr/bin/defaults -currentHost write com.apple.screensaver moduleDict -dict moduleName -string "iLifeSlideshows" path -string "/System/Library/Frameworks/ScreenSaver.framework/Resources/iLifeSlideshows.saver" type -int 0
fi

## additional configuration settings for screensaver framework
/usr/bin/sudo -u $user /usr/bin/defaults -currentHost write com.apple.screensaver tokenRemovalAction -int 0
/usr/bin/sudo -u $user /usr/bin/defaults -currentHost write com.apple.ScreenSaverPhotoChooser LastViewedPhotoPath -string ""
/usr/bin/sudo -u $user /usr/bin/defaults -currentHost write com.apple.ScreenSaverPhotoChooser SelectedFolderPath -string "/Library/Screen Savers/Default Collections/CompanyName/"
/usr/bin/sudo -u $user /usr/bin/defaults -currentHost write com.apple.ScreenSaverPhotoChooser SelectedSource -int 3
/usr/bin/sudo -u $user /usr/bin/defaults -currentHost write com.apple.ScreenSaverPhotoChooser ShufflesPhotos -bool "false"
/usr/bin/sudo -u $user /usr/bin/defaults -currentHost write com.apple.ScreenSaver.iLifeSlideShows styleKey -string "Classic"
/usr/bin/sudo /usr/bin/killall -hup cfprefsd
exit 0

sfaeder
New Contributor III

This worked well for me. Thank you stranger!

dpratl
Contributor II

Hi @smpotter,

Thank you very much for this script. It is also working on an M1 MacBook and Big Sur!

BR
Daniel

PaulS_CUKL
New Contributor II

Does anyone know the variables for the -stylekey string? im looking for Vintage Prints but can't figure it out...

shrisivakumaran
New Contributor III

is it still working? tested in Catalina and Monterey its not working, screensaver is not working with custom image. does anyone have working scripts or policy?

Shri Sivakumaran

BagaleAnil
New Contributor

@smpotter this script is not working on Sonoma.

Do we need to modify it for Sonoma OS?