Skip to main content
Question

Disable User's Screen Lock in OSX

  • May 13, 2016
  • 3 replies
  • 23 views

Forum|alt.badge.img+4

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

sdagley
Forum|alt.badge.img+25
  • Jamf Heroes
  • May 13, 2016

$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
Forum|alt.badge.img+35
  • Hall of Fame
  • May 15, 2016

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


Forum|alt.badge.img
  • New Contributor
  • May 29, 2018

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