Category filter
Script to set screen saver on Mac
Configured to be activated after a specific period of device inactivity, screen saver plays a crucial role in protecting confidential information when the users are away from the device screen. This doc helps you configure screen saver on macOS devices using a script that can be executed with Hexnode’s Execute Custom Script action. The script lets you set up a screen saver photo slideshow across the devices.
Scripting language – Bash
File extension – .sh
Set slideshow screen saver
Here’s a sample script to set a screen saver photo slideshow. You can set the images to be displayed, the idle time after which the screen saver needs to be enabled, the slideshow style, and also choose to shuffle the images
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
#!/bin/sh Style='Shifting Tiles' IdleTime='60' ShufflePhotos='true' PhotosFolderPath=$1 Style=$(tr -d ' ','-' <<< $Style) loggedInUser=`stat -f%Su /dev/console` echo "The currently logged-in user: $loggedInUser" sudo su $loggedInUser -c ' osVersion=$(sw_vers -productVersion) osMajor=$(echo $osVersion | cut -d '.' -f 1) osMinor=$(echo $osVersion | cut -d '.' -f 2) osPatch=$(echo $osVersion | cut -d '.' -f 3) defaults write com.apple.screensaver askForPassword -int 1 defaults write com.apple.screensaver askForPasswordDelay -int 1 defaults -currentHost write com.apple.screensaver 'CleanExit' -string "YES" defaults -currentHost write com.apple.screensaver 'PrefsVersion' -int "100" defaults -currentHost write com.apple.screensaver 'idleTime' -int '$IdleTime' defaults -currentHost write com.apple.ScreenSaverPhotoChooser SelectedFolderPath -string '$1' defaults -currentHost write com.apple.ScreenSaverPhotoChooser SelectedSource -int 4 defaults -currentHost write com.apple.ScreenSaver.iLifeSlideShows styleKey -string '$Style' defaults -currentHost write com.apple.ScreenSaverPhotoChooser 'ShufflesPhotos' -bool '$ShufflePhotos' defaults -currentHost write com.apple.screensaver moduleDict -dict-add moduleName 'iLifeSlideshows' if [[ $osMajor -lt 10 || ( $osMajor -eq 10 && $osMinor -lt 14 ) || ( $osMajor -eq 10 && $osMinor -eq 14 && $osPatch -lt 2 ) ]]; then defaults -currentHost write com.apple.screensaver moduleDict -dict-add path '/System/Library/Frameworks/ScreenSaver.framework/Resources/iLifeSlideshows.saver' else defaults -currentHost write com.apple.screensaver moduleDict -dict-add path '/System/Library/Frameworks/ScreenSaver.framework/PlugIns/iLifeSlideshows.appex' fi ## Removes the .plist LaunchAgent from inside the User Launch Agent Folder. rm -f ~/Library/LaunchAgents/set-screensaver.plist killall cfprefsd exit; ' echo "The Screen Saver has been set to $Style" |
Style
– This field takes into consideration the style of the slideshow to be deployed. Provide the name of the style you would like to set on the device. Apple provides a bunch of options you can choose from:
- Floating
- Flip-up
- Reflections
- Origami
- Shifting Tiles
- Sliding Panels
- Photo Mobile
- Holiday Mobile
- Photo Wall
- Vintage Prints
- Ken Burns
- Classic
IdleTime
– Provide the inactivity period (in seconds) after which the screen saver should activate. The value ‘0’ sets the screen saver to be never activated.
ShufflePhotos
– Provide ‘true’ or ‘false’ based on whether you want the images for the slideshow to be shuffled. If the value is set as ‘false’, the images will be displayed in the order they appear in the source folder.
Photosfolderpath
– Provide the path to the folder that contains the images for the slideshow as an argument. For example, to deploy a slideshow screen saver for images stored at ‘/Users/jacob/Desktop/ScreenSavers’, specify it in the Arguments field while executing the action.