Back to Resources
Level
Script
Maintenance
By default, macOS may allow a device to enter sleep mode even when it’s connected to a power source, disrupting remote sessions, ongoing tasks, or important server functions. This script addresses that challenge by preventing unwanted sleep events while the device is plugged into AC power, ensuring smooth, continuous operation.
This script uses the pmset
command to adjust power management settings in macOS specifically for AC power usage. It disables system sleep, disk sleep, idle sleep, auto power off, and standby mode when the Mac is plugged in. After applying these new settings, it provides a confirmation by displaying the updated power configuration, giving you immediate visibility into the changes made.
#!/bin/bash
# This resource is provided as a convenience for Level users. We cannot
# guarantee it will work in all environments. Please test before deploying
# to your production environment. We welcome contributions to our community
# library
# Level Library
# https://level.io/library/script-macos-disable-sleep-on-ac-power
echo "Disabling macOS sleep settings when plugged into power (AC)..."
# Disable system sleep when on AC power
sudo pmset -c sleep 0
# Prevent disk sleep when on AC power
sudo pmset -c disksleep 0
# Prevent idle sleep when on AC power
sudo pmset -c disablesleep 1
# Prevent system from hibernating when on AC power
sudo pmset -c autopoweroff 0
# Prevent the system from entering standby mode when on AC power
sudo pmset -c standby 0
# Verify changes
echo "Updated power settings for AC power:"
pmset -g
echo "Sleep has been disabled while plugged in."
pmset -g
. You can also check in System Settings > Energy Saver.pmset restoredefaults
from a terminal with sudo privileges.macOS - Disable Sleep on AC Power
This Bash script modifies macOS power management settings to prevent the system from entering sleep, disk sleep, idle sleep, hibernation, or standby modes while connected to AC power (when plugged in), using the pmset
command to adjust various power-related parameters and displaying the updated settings upon completion. The script is part of the Level library of resources and includes appropriate warnings about testing before production deployment.
Bash
100
Local system
Explore more automations, scripts, and policies to further enhance your IT operations.