Back to Resources

Level Verified

macOS Disable Sleep on AC Power Script

Created by

Level

Type

Script

Category

Maintenance

Platforms
WindowsApple iOSLinux

Problem Overview

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.

Description

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.

Script

#!/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."

Use Cases

  • Maintaining reliable remote access to headless or unattended Mac servers
  • Ensuring background tasks and processes remain uninterrupted
  • Running continuous workflows or kiosk sessions without downtime
  • Preventing any unexpected sleep during critical updates or backups

Recommendations

  • Test this script on a non-production or test device to confirm it applies correctly
  • Use Level to run this on newly added devices or as part of a setup automation to ensure you have consistent remote access
  • If you need this applied regularly, create an Automation in Level with a scheduled trigger to ensure the settings remain enforced

FAQ

  • Does this affect battery operation?
    No. It only modifies power settings when the Mac is on AC power.
  • Will I need admin rights to run it?
    Yes. Changing system-level settings such as power management requires elevated privileges.
  • How can I confirm it’s working?
    The script displays the updated power settings using pmset -g. You can also check in System Settings > Energy Saver.
  • Can I revert to the original settings?
    Yes. You can manually restore defaults via System Settings, or run pmset restoredefaults from a terminal with sudo privileges.
  • Why might it fail to disable sleep?
    Check for mobile device management (MDM) or other policy profiles that override local power settings.

Included with this Script:

Below is a list of what you can expect to find when importing this Script.

Script details:

The following data and settings will be imported with your script.

Script Name

macOS - Disable Sleep on AC Power

Description

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.

Language

Bash

Timeout (In Seconds)

100

Run As

Local system

Import into Level

Related resources

Explore more automations, scripts, and policies to further enhance your IT operations.

View all resources