Category filter
Script to enable password for screen lock on Mac
Strong passwords ensure protection against unauthorized access to your macOS devices. Administrators can remotely set the Mac to require a password when it wakes from sleep with the help of scripts in Hexnode. Enabling a password will keep the data on the Mac secure when users are away from it. Hexnode helps admins perform this action with the help of Execute Custom Script feature.
Scripting language – Bash
File extension – .sh
Enable password for screen lock
The below code uses the osascript
command to run an AppleScript line:
1 |
osascript -e 'tell application "System Events" to set require password to wake of security preferences to true' |
osascript –e
– Runs the main AppleScript command from within the Shell environment. The ‘osascript’ command with the ‘-e’ parameter is used to execute the AppleScript command directly within a shell environment.
tell application "System Events" to set require password to wake of security preferences to true
– Use System Events to automatically enable the ‘Require password __ after sleep or screensaver begins’ checkbox under System Preferences > Security & Privacy > General without any prompts. When the option is enabled on the device, the delay for ‘Require password __ after sleep or screensaver begins’ is set to immediately. When the device goes to sleep or when the screensaver is activated, the device enables the password immediately.
What happens at the device end?
After executing the script from the portal, it enables the Require password after sleep or screen saver begins settings under System Preferences > Security & Privacy > General.
If the System Preferences is kept open on the device when the script is executed from the portal, you may have to exit and open the System Preferences again for the script to take effect.