Skip to main content
Solved

Custom ScreenSaver script is not working on Big Sur.

  • February 4, 2021
  • 9 replies
  • 30 views

Forum|alt.badge.img+3
  • New Contributor
  • 5 replies

I believe the issue is with the OS version line (Major and Minor), but I have very little experience in creating scripts.

!/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 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

Best answer by Tribruin

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.

9 replies

Forum|alt.badge.img+19
  • Honored Contributor
  • 582 replies
  • Answer
  • February 4, 2021

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.


pete_c
Forum|alt.badge.img+16
  • Honored Contributor
  • 258 replies
  • February 5, 2021

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 }}' )

Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 5 replies
  • February 18, 2021

Thank you @RBlount and @pete_c for your recommendations.


Forum|alt.badge.img+1
  • New Contributor
  • 3 replies
  • March 17, 2021

@JSOTO I'm having the same issue; can you share the solution that worked for you?


SmilieK
Forum|alt.badge.img+7
  • New Contributor
  • 23 replies
  • April 29, 2021

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

Forum|alt.badge.img+2
  • New Contributor
  • 1 reply
  • September 30, 2021

Hi all, I don't suppose anyone has a working script for 11.6? 


Forum|alt.badge.img+1
  • New Contributor
  • 2 replies
  • February 14, 2022

Hi all, I don't suppose anyone has a working script for 11.6? 


anyone working with script 12.2


pete_c
Forum|alt.badge.img+16
  • Honored Contributor
  • 258 replies
  • April 6, 2022

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

 


Forum|alt.badge.img+4
  • New Contributor
  • 9 replies
  • October 6, 2023

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.