require password on wake (Sierra)

I need to activate the security preference "require password on wake" from a script.

A simple AppleScript worked fine:

osascript -e 'tell application "System Events" to set require password to wake of security preferences to true'

That worked up to Sierra but does no longer since I upgraded.


Any hints how to overcome the problem?

I'm having the same issue. The apple script
tellapplication "System Events" toset require password to wake of security preferences totrue
doesn't work anymore in macOS Sierra. The problem seems to be specific to the "require password to wake" property. For instance, tellapplication "System Events" toset dark mode of appearance preferences totrue
still works fine (sets the menubar to dark mode).


What you can do instead is run the following in a terminal:

defaults write 'com.apple.screensaver' 'askForPassword' -int 1

However, those changes won't be effective unless you reboot (or at least logout and login again).


Does someone know a way to make this work again?

Thanks, that at least provided a useful idea for a workaround.


The initial question is still open, though, any further hints are still welcome!


BTW, for those who are interested here's a bit of background:

in some settings (like mine) it would be awkward to have the password enabled all the time - it's only necessary when carrying the laptop outside.

So, naturally I keep forgetting enabling the password BEFORE leaving. Thus, I wrote a script that detects whether I'm home and if not, it activates the password and sends the laptop to sleep. Next time somebody wakes it up the password is required. Not waterproof, but better than nothing...

Since this scheme no longer works with Sierra, the script forces a log-out instead of just sleep mode.

require password on wake (Sierra)
 
 
Q