Category Filter

Script to configure sleep settings for Mac

Users will typically select the Apple icon from the menu bar and select Sleep to put a device in the sleep state. To configure the display sleep settings, they will have to open System Preferences > Battery. From there, they may set the Turn display off after duration and schedule sleep/wake-up events. Device admins might want to configure these options remotely with the below shell scripts.

You can remotely run scripts on Macs managed with Hexnode using the Execute Custom Script action.

Scripting Language – Bash

File extension – .sh

Disclaimer:


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

Manage Power Settings on Mac

With the power management settings pmset command, we can manage settings like idle sleep timing, wake on administrative access, automatic restart on power loss, etc.

This command will set the system sleep timer to 15 minutes i.e., the system will automatically sleep after 15 minutes of inactivity.

This command will set the display sleep timer to 15 minutes i.e., the system will turn off the device display after 15 minutes of inactivity.

This command will wake or power on the system every day at 9:00 am. Here, MTWRFSU represents the weekdays as –

M – Monday

T – Tuesday

W – Wednesday

R – Thursday

F – Friday

S – Saturday

U – Sunday

Examples –

  • sudo pmset repeat shutdown F 20:00:00

    This command will shut down the system every Friday at 8:00 pm.

  • sudo pmset repeat cancel

    This command will cancel all repeating pmset events.

  • sudo pmset –g

    This command will return the system-wide power settings.

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.