Running commands at the local user

PaulS_CUKL
New Contributor II

Hi All

I'm trying to run a command to set a screen saver option as the current logged in user through a script but it's failing... I have tried looking around for ways to run as the local user instead of the root user used by Jamf and I can get it to add "/Library/Screen" the local user plist file but not the full location "/Library/Screen Savers/Default Collections/5 - Company", can any one shed some light on where i'm going wrong, I'm going square eyed looking at this over and over

My script is:

!/bin/bash

currentuser=$(/bin/ls -la /dev/console | /usr/bin/cut -d ' ' -f 4)
su -l $currentuser -c "defaults write /Users/$currentuser/Library/Preferences/com.apple.ScreenSaverPhotoChooser SelectedFolderPath '/Library/Screen Savers/Default Collections/5 - Company'"

Any help is very much appreciated....

1 REPLY 1

amccarty
New Contributor III

Here's the script I've used previously for setting the Screensaver. It works great, there's some additional options in there for things like idle time, so just modify it based on your requirements.

#!/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 ]]; 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 SelectedFolderPath -string "/Library/Application Support/JAMF/bin/screensaver"
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