Making askForPasswordDelay for Screensaver preference change immediately effective

sdeepak13
New Contributor

Hi,

I'm currently trying to implement a password requirement for Screensaver on Mac OSX, with delay of 5 seconds. This works and changes the setting in system preferences, but require the user to log out or restart to go into effect. I'd like to add something to make it effective immediately and could use some help.

In threads I've found I've heard talk that it's like some process is running and is referencing cached preference settings instead of the new ones. That makes sense. But I don't know what the process is. I've tried "killall cfprefsd" but that's doesn't seem to work.

#!/bin/sh

#looks for the logged in username
user=$(stat -f '%Su' /dev/console)


#turns password requirement on for gui preference
sudo -u $user defaults write com.apple.screensaver askForPassword -int 1

#set the delay in gui preference in seconds.  
sudo -u $user defaults write com.apple.screensaver askForPasswordDelay -int 5
3 REPLIES 3

mm2270
Legendary Contributor III

Why not use a Configuration Profile for this instead of a defaults write command? I believe it will take effect immediately when deployed via Config Profile.
Or is there some reason I'm not seeing that this needs to be a scripted solution?

gachowski
Valued Contributor II

This should get you going in the right direction ...

https://www.jamf.com/jamf-nation/discussions/18574/user-password-policies-on-non-ad-machines

and the profile way....

https://developer.apple.com/library/content/featuredarticles/iPhoneConfigurationProfileRef/Introduction/Introduction.html

mcw
New Contributor

Using defaults write no longer works as of 10.13.

https://blog.kolide.com/screensaver-security-on-macos-10-13-is-broken-a385726e2ae2
http://www.openradar.me/35462422

For those who have been searching for a way to do this via profiles, you can use this gist: https://gist.github.com/mcw0933/21b8a9e292e83c69931f5de0d2ae1883

This does take effect immediately.