Worklet to set screen lock on Mac

My company is working on making sure we have automatic screen lockouts on our machines. For our Windows machines we control this through GPO, but that does not affect the handful of Mac machines we have in our environment.

Does anyone know how to script out a way to have Macs lock after a certain amount of inactivity (i.e. 5 minutes)? My DuckDuckGoing has been unsuccessful in searching for an answer to this.


Looking into it, it seems like using the osascript command might be the way to go (haven’t tested it yet). Here’s a basic whack at a worklet to set up the screensaver initiation time and toggle on the password to exit the screensaver (or wake from sleep):
Evaluation code(this is set with a hardcoded exit to always run on scheduled time):
exit 1

Remediation code:

#Set screensaver activation time to 30 secs after last action
sudo osascript -e ‘tell application “System Events” to set delay interval of screen saver preferences to 30’
#Set password exit requirement
sudo osascript -e ‘tell application “System Events” to set require password to wake of security preferences to true’

exit 0

Feel free to give it a try and let us know if it works out.