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 command.

Scripting Language – Bash

File extension – .sh

Disclaimer:


The Sample Scripts provided below are adapted from third-party Open-Source sites.

Enable Password for Screen Lock

The below code uses the osascript command to run an AppleScript line:

osascript –e – Runs the main AppleScript command from within the 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 without any prompts. If the System Preferences is kept open 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.

Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.