Disable User's Screen Lock in OSX

cdenoia
New Contributor

Issue: All Self Service policies run as Root.
Objective: Disable User's Screen Lock

#!/bin/sh

Capture 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 false

Update local ACL

chown $user:staff $path.plist

Finish

exit 0
3 REPLIES 3

sdagley
Honored Contributor II

$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

bentoms
Honored Contributor III
Honored Contributor III

$3 works when invoked via Self Service as per this article.

SAhrens
New Contributor

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