Level Verified

macOS Disable Sleep on AC Power Script

Keep your Mac awake while plugged into power. This script disables default sleep behaviors, ensuring continuous remote access, uninterrupted processes, and stable system performance when running on AC power.

Import into Level

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.

Bash 100s timeout Runs as Local system macOS
#!/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."

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.

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

Frequently asked questions.

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.

Ready when you are.

No credit card. No sales call. Just sign up and start managing.