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


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.

This command will prevent the system from sleeping for 300 seconds from the time it is executed. The time is specified in seconds here.

This command will report the number of idle minutes the system waits before it sleeps. If the output is Never, it indicates that the system’s sleep function is off.

This command turns off the system’s sleep function.

This command ensures that the system automatically restarts if it freezes.


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

  • Sample Script Repository