How to Use the pmset and caffeinate Commands in macOS for Advanced Power Management and Sleep Assertion

On Apple silicon and Intel-based Mac systems running macOS, battery longevity and thermal performance are regulated by the Darwin Power Management subsystem via Apple’s I/O Kit framework. While the graphical user interface in macOS System Settings provides basic power sliders, it obscures granular system directives such as hibernation depth, standby delays, network keepalives, and scheduled power events. For systems administrators, developers executing long-running compilation scripts, and audio/video engineers rendering intensive timelines, low-level power control is essential.

macOS natively provides two command-line utilities for this purpose: pmset (Power Management Settings) and caffeinate. The pmset command enables administrators to inspect, configure, and schedule system-wide hardware power states, while caffeinate dynamically injects temporary power assertions into the kernel to prevent idle or display sleep during critical operations.


Architectural Overview: I/O Kit Power Assertions and Sleep States

Power management in macOS operates through a contract between user-space applications and the Darwin kernel known as Power Assertions. When an application initiates a task that requires sustained execution (such as downloading a large asset or playing audio), it issues an assertion via IOPMAssertionCreateWithName(). The kernel aggregates these assertions, evaluating whether the hardware can safely transition between three distinct low-power states:

  • Idle Sleep: Displays turn off, CPU clock frequencies drop to minimal idling states, but RAM remains powered and peripheral buses stay live.
  • Standby (Safe Sleep): The contents of active RAM are mirrored to the non-volatile NVMe storage volume (/var/vm/sleepimage). Power to main memory is sustained unless battery reserves drop past a defined threshold.
  • Deep Hibernation: Power to the RAM modules is cut entirely; restoring system state requires reading the saved memory image back from the SSD into RAM upon boot.
Setting / Value Kernel Mechanism RAM Power State Storage Impact Primary Use Case
hibernatemode 0 Legacy desktop sleep Continuously powered Zero disk writes; no sleepimage used Mac Studio, Mac mini, or Mac Pro on constant mains power
hibernatemode 3 Standard portable safe sleep Powered, backed up to SSD Writes RAM contents to sleepimage on sleep Default for MacBook Air and MacBook Pro laptops
hibernatemode 25 Immediate deep hibernation Power cut immediately upon sleep Full memory write; zeroes battery draw during sleep Long-term travel, critical battery conservation

Querying System Power States and Diagnosing Sleep Blocks

Before applying custom power profiles, inspect the active configuration and identify any running processes that currently hold active sleep assertions preventing your Mac from idling.

Step 1: Inspect Current Power Settings

Open Terminal and view the active power management parameters:

# Display current settings for active power source
pmset -g

# Display all settings across battery, AC charger, and UPS
pmset -g custom

The output displays configuration flags such as sleep, displaysleep, disksleep, and standbydelayhigh, with an asterisk (*) marking the currently active power profile.

Step 2: Inspect Active Power Assertions

If your Mac displays erratic sleep behaviour or drains battery with the lid closed, audit active kernel assertions:

# List all active system sleep assertions and their owning PIDs
pmset -g assertions

Review the output for keys such as PreventUserIdleSystemSleep, PreventSystemSleep, and PreventUserIdleDisplaySleep. Under each section, macOS identifies the specific process name and Process ID (PID) responsible for maintaining the wake lock.

Assertion Status Sample:
   PreventUserIdleSystemSleep             1
   PreventUserIdleDisplaySleep            0
   PreventSystemSleep                     0
   Listed by owning process:
     pid 412(coreaudiod): [0x0000003b00018150] 00:14:22 PreventUserIdleSystemSleep named: "com.apple.audio.AppleHDAEngineOutput:1B,0,1,1:0.context.preventidle"

Configuring Advanced System Behaviour with pmset

The pmset utility accepts target power domain flags to apply configurations conditionally based on hardware power source:

  • -b: Apply exclusively to Battery operation
  • -c: Apply exclusively to Mains Charger / AC power
  • -u: Apply to Uninterruptible Power Supply (UPS)
  • -a: Apply universally across All power profiles

Optimising Standby Delay and Hibernation

To reduce overnight battery drain on portable MacBooks, configure the system to transition into deep standby more aggressively when operating on battery:

# Set display sleep to 5 minutes on battery, 15 minutes on AC
sudo pmset -b displaysleep 5
sudo pmset -c displaysleep 15

# Set system idle sleep to 10 minutes on battery
sudo pmset -b sleep 10

# Configure high-battery standby threshold (delay in seconds: 3600 = 1 hour)
sudo pmset -b standbydelayhigh 3600

# Configure low-battery standby threshold (delay in seconds: 300 = 5 minutes)
sudo pmset -b standbydelaylow 300

# Set battery percentage threshold that differentiates high from low standby delay
sudo pmset -a highstandbythreshold 50

Managing Network Wake Locks and TCP Keepalives

Background network activity frequently wakes sleeping Mac laptops inside carrying bags, generating excessive heat and depleting the battery. Disable network wake timers on battery while retaining wake-on-LAN over AC:

# Disable Wake on Network Access (Wake-on-LAN) when running on battery
sudo pmset -b womp 0

# Enable Wake on Network Access on mains charger for administrative management
sudo pmset -c womp 1

# Disable TCP keepalives during sleep on battery to eliminate background fetching
sudo pmset -b tcpkeepalive 0

Warning: Disabling tcpkeepalive may limit Find My location updating while the MacBook is asleep on battery. Evaluate this trade-off if physical tracking is a priority.

Scheduling Automated Power Events

For administrative staging, remote backup tasks, or automated testing environments, pmset supports automated wake, power-on, and sleep triggers:

# Schedule Mac to wake or power on every weekday at 07:30 AM
sudo pmset repeat wakeorpoweron MTWRF 07:30:00

# Schedule shutdown every evening at 23:00 PM
sudo pmset repeat shutdown MTWRFSU 23:00:00

# Inspect currently scheduled power events
pmset -g sched

# Cancel all scheduled repeat power routines
sudo pmset repeat cancel

Preventing Sleep with the caffeinate Utility

Rather than altering persistent global power profiles, administrators and engineers can invoke caffeinate to temporarily hold power assertions during critical workflows, eliminating the need for third-party helper applications.

Command-Line Syntax and Assertion Flags

Flag Assertion Type Functional Behaviour
-d Create PreventUserIdleDisplaySleep Forces displays to remain illuminated and active
-i Create PreventUserIdleSystemSleep Prevents overall system sleep; displays may sleep normally
-m Create PreventDiskIdleSleep Forces internal and external storage drives to remain spun up
-s Create PreventSystemSleep Prevents system from sleeping when connected to AC power
-u Create UserIsActive Emulates active user presence at the console interface
-t [seconds] Timed Timeout Specifies assertion duration before automatic termination
-w [pid] Process Watcher Maintains assertion until the specified Process ID exits

Practical Implementation Examples

Example 1: Running a Timed Assertion

To prevent display and system sleep for a defined duration (such as a 45-minute presentation or file transfer), supply duration in seconds:

# Keep system and display awake for 2700 seconds (45 minutes)
caffeinate -d -i -t 2700

Example 2: Wrapping a Shell Command or Script

When executing extensive compilation, machine learning model training, or rsync synchronisation, wrap the command directly within caffeinate. The assertion terminates automatically the moment the wrapped process finishes:

# Keep system and storage awake during extensive directory synchronisation
caffeinate -ims rsync -avzh /Volumes/ProductionData/ /Volumes/BackupStorage/

Example 3: Attaching to an Existing Long-Running Process

If an export or rendering job is already underway in an application such as Final Cut Pro or Blender, attach an assertion to its PID:

# Locate process ID of target software
pgrep -x "Blender"

# Attach sleep prevention assertion to PID 3892
caffeinate -i -w 3892 &

Troubleshooting Common macOS Power and Sleep Faults

Symptom Underlying Cause Remediation Procedure
MacBook wakes up hot inside laptop sleeve/bag womp (wake on LAN) or powernap triggered by background push services Execute sudo pmset -b womp 0 and disable Power Nap. Verify active wake reasons with log show --predicate 'eventMessage contains "Wake reason"' --last 2h.
System refuses to sleep even when idle timers elapse Orphaned background process holding PreventUserIdleSystemSleep Run pmset -g assertions to identify the owning PID. Terminate the offending process using kill -9 <PID> or restart the associated daemon.
pmset commands return Unable to set: 0xe00002bc Insufficient privileges or setting not supported on Apple silicon hardware Prefix command with sudo. Note that certain legacy Intel directives (such as sms sudden motion sensor) do not apply to M-series hardware.
Excessive storage consumption by /var/vm/sleepimage hibernatemode 3 reserves a sleepimage file equivalent to system RAM size If running a desktop Mac on steady UPS power, switch to sudo pmset -a hibernatemode 0 and delete the image with sudo rm -f /var/vm/sleepimage.

Maintenance and Configuration Governance

  • Audit Assertions After System Updates: Major macOS version upgrades may reset energy preferences to defaults or modify default standby thresholds. Maintain a deployment shell script to reapply corporate or personal power preferences.
  • Restore Factory Defaults when Troubleshooting: If power settings become unstable or contradictory, revert to Apple factory baseline states by executing sudo pmset -a restoredefaults followed by an SMC/NVRAM reset on Intel Macs or a clean restart on Apple silicon.
  • Prefer Caffeinate over Third-Party Utilities: Third-party menu bar utilities often install legacy helper daemons and consume unnecessary memory. Employ native caffeinate commands or lightweight shell aliases for clean, dependency-free assertion handling.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.