Skip to content

power_profile_macos.sh

Corey Watson edited this page Dec 1, 2025 · 1 revision

power_profile_macos.sh

Configures an "always-on" power profile for macOS devices with optimized settings for laptops and desktops.

Overview

This script sets power management preferences on macOS to keep systems available while balancing energy efficiency. It automatically detects whether the device is a laptop or desktop and applies appropriate power settings for each scenario.

Purpose

Provides standardized power management configuration for managed macOS devices, ensuring systems remain accessible for remote management while implementing sensible sleep policies based on device type and power source.

Prerequisites

  • Operating System: macOS 10.12 or later
  • Privileges: Root/sudo privileges required
  • Utilities: pmset (standard macOS component)

Configuration

Required Inputs

All settings are hardcoded in the script:

AC Power Settings (All Devices):

  • Display sleep: 30 minutes
  • Disk sleep: 60 minutes
  • System sleep: Never (desktops) / Default (laptops)

Battery Power Settings (Laptops Only):

  • Display sleep: 10 minutes
  • Disk sleep: 30 minutes
  • System sleep: 20 minutes

Hibernation:

  • Disabled for desktops
  • Default for laptops

No parameters required - all settings are embedded in the script.

Behavior

  1. Root Check: Verifies script is run with sudo privileges
  2. Battery Detection:
    • Uses pmset -g batt to detect battery presence
    • Identifies device as laptop or desktop
    • Displays detection result
  3. Display Sleep Configuration:
    • Sets 30 minutes on AC power (all devices)
    • Sets 10 minutes on battery (laptops only)
  4. Disk Sleep Configuration:
    • Sets 60 minutes on AC power (all devices)
    • Sets 30 minutes on battery (laptops only)
  5. System Sleep Configuration:
    • Desktops: Disables system sleep on AC power (sleep 0)
    • Laptops: Sets 20 minutes on battery power
  6. Hibernation Configuration:
    • Desktops: Disables hibernation (hibernatemode 0)
    • Laptops: Leaves default hibernation settings
  7. Verification: Reports success for each setting

The script exits immediately on any command failure due to set -euo pipefail.

Security Notes

  • Requires root privileges to modify system power settings
  • No network access required
  • No credentials stored or transmitted
  • All settings stored in standard macOS power management configuration
  • Changes take effect immediately

Exit Codes

  • 0: Power settings configured successfully
  • 1: Configuration failed:
    • Script not run as root
    • pmset command failed for any setting

Example Output

Desktop System:

[ POWER PROFILE ALWAYS-ON - macOS ]
--------------------------------------------------------------

[ SYSTEM CHECK ]
--------------------------------------------------------------
Battery Status : NOT DETECTED (Desktop)

[ APPLYING POWER SETTINGS ]
--------------------------------------------------------------
Display Sleep (AC)    : 30 minutes
Display Sleep (DC)    : 10 minutes
Disk Sleep (AC)       : 60 minutes
Disk Sleep (DC)       : 30 minutes
System Sleep (AC)     : Never (0)

[ CONFIGURING HIBERNATION ]
--------------------------------------------------------------
Hibernation           : DISABLED (Desktop)

[ FINAL STATUS ]
--------------------------------------------------------------
Result : SUCCESS
Power settings configured successfully

[ SCRIPT COMPLETED ]
--------------------------------------------------------------

Laptop System:

[ POWER PROFILE ALWAYS-ON - macOS ]
--------------------------------------------------------------

[ SYSTEM CHECK ]
--------------------------------------------------------------
Battery Status : DETECTED (Laptop)

[ APPLYING POWER SETTINGS ]
--------------------------------------------------------------
Display Sleep (AC)    : 30 minutes
Display Sleep (DC)    : 10 minutes
Disk Sleep (AC)       : 60 minutes
Disk Sleep (DC)       : 30 minutes
System Sleep (DC)     : 20 minutes

[ CONFIGURING HIBERNATION ]
--------------------------------------------------------------
Hibernation           : Enabled (Laptop default)

[ FINAL STATUS ]
--------------------------------------------------------------
Result : SUCCESS
Power settings configured successfully

[ SCRIPT COMPLETED ]
--------------------------------------------------------------

Version History

  • v1.0.0: Initial release
    • Automatic laptop/desktop detection
    • Differentiated AC and battery settings
    • Optimized sleep timers for remote management
    • Hibernation configuration based on device type

Links

Clone this wiki locally