Posted on 02-04-2021 01:52 PM
I believe the issue is with the OS version line (Major and Minor), but I have very little experience in creating scripts.
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 600
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/Application Support/JAMF/bin/image"
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
Solved! Go to Solution.
Posted on 02-04-2021 02:56 PM
Take a look at this article. macOS Version Big Sur Update. It looks like you are probably correct that the version is coming out wrong.
Try adding the following line to your script BEFORE it checks the versions
export SYSTEM_VERSION_COMPAT=1
That should force the OS to return 10.16 as the product version instead of 11.X. (Surprisingly it returns 10.16, not 10.16.X, but that should be OK in your script as long as 16 is always greater than 15.
Posted on 02-04-2021 02:56 PM
Take a look at this article. macOS Version Big Sur Update. It looks like you are probably correct that the version is coming out wrong.
Try adding the following line to your script BEFORE it checks the versions
export SYSTEM_VERSION_COMPAT=1
That should force the OS to return 10.16 as the product version instead of 11.X. (Surprisingly it returns 10.16, not 10.16.X, but that should be OK in your script as long as 16 is always greater than 15.
Posted on 02-05-2021 10:18 AM
You also should avoid parsing ls for the current user.
Try replacing your first line with:
user=$( scutil <<< "show State:/Users/ConsoleUser" | awk -F': ' '/[[:space:]]+Name[[:space:]]:/ { if ( $2 != "loginwindow" ) { print $2 }}' )
Posted on 02-18-2021 05:52 AM
Posted on 03-17-2021 11:17 AM
@JSOTO I'm having the same issue; can you share the solution that worked for you?
Posted on 04-29-2021 06:43 AM
Use OS Build Versions not OS versions here:
## macOS Build Versions Reference
# Build 17 is High Sierra
# Build 18 is Mojave
# Build 19 is Catalina
# Build 20 is Big Sur
# Build 21 is <TBD - Summer 2021>
# You could also look for the First letter in the Build number for the minor release number A= .1, B=.2, C=.3, D=.4, E=.5, etc
lookingForVersion="18" # or Higher
echo "Current macOS Build Version: $(sw_vers -buildVersion)"
# check if $lookingForVersion or higher is installed
if [[ $(sw_vers -buildVersion) > "$lookingForVersion" ]]; then
# This would run for macOS Mojave and Higher based on lookingForVersion being "18"
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
# This would run on macOS High Serria and Older based on lookingForVersion being "18"
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
Posted on 09-30-2021 04:32 AM
Hi all, I don't suppose anyone has a working script for 11.6?
Posted on 02-14-2022 09:51 AM
anyone working with script 12.2
Posted on 04-06-2022 09:33 AM
Currently using this version, BUT: if you open System Preferences > Desktop & Screen Saver BEFORE the saver has activated (timer, hot corner), Big Sur 11.6.5 will default to Message and Monterey 12.3+ will default to Monterey. If you allow the screen saver to activate, the correct saver runs with the options specified.
I have not tested this solution with other savers to determine if its a bug specific to Classic or any of the other photo savers (which have been horribly broken since BS).
#!/bin/bash
# https://community.jamf.com/t5/jamf-pro/catalina-screensaver/m-p/177197/highlight/true#M166063
## get current user
user=$( scutil <<< "show State:/Users/ConsoleUser" | awk -F': ' '/[[:space:]]+Name[[:space:]]:/ { if ( $2 != "loginwindow" ) { print $2 }}' )
## 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 600
## 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 "/path/to/image/folder"
/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
Posted on 10-06-2023 02:08 PM
Hi,
Has anyone resolved this issue for Sonoma? I can see the 3 pref files (com.apple.screensaver, com.apple.ScreensaverPhotoChooser, and com.apple.ScreenSaver.iLifeSlideShows) are updating with the script, but I still don't have any luck with the screensaver changing.