Posted on 05-13-2016 06:55 AM
Issue: All Self Service policies run as Root.
Objective: Disable User's Screen Lock
#!/bin/shCapture Active User
user=$(ls -l /dev/console | awk {' print $3 '})Navigate to User Dir
path="/Users/$user/Library/Preferences/com.apple.screensaver"Disable Screen Lock
defaults write "$path" askForPassword -int 0 defaults write "$path" idleTime -int 7200 defaults write "$path" askForPassword -bool falseUpdate local ACL
chown $user:staff $path.plistFinish
exit 0
Posted on 05-13-2016 08:41 AM
$3 is only the current user if the script is being run as a login policy.
Here's a previous previously posted thread on how to find the current user if you're not running at login: Running a script as the logged in user
Posted on 05-15-2016 02:59 AM
$3 works when invoked via Self Service as per this article.
Posted on 05-29-2018 01:42 AM
I modified the script this way:
Objective was to run it on a specific set of machines after login without involving the users.
#!/bin/sh
path="/Users/$3/Library/Preferences/com.apple.screensaver"
su - $3 -c "defaults write "$path" askForPassword -int 0"
su - $3 -c "defaults write "$path" idleTime -int 7200"
su - $3 -c "defaults write "$path" askForPassword -bool false"
su - $3 -c "chown $3:staff $path.plist"
exit 0