-
Notifications
You must be signed in to change notification settings - Fork 5
power_profile_macos.sh
Configures an "always-on" power profile for macOS devices with optimized settings for laptops and desktops.
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.
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.
- Operating System: macOS 10.12 or later
- Privileges: Root/sudo privileges required
- Utilities: pmset (standard macOS component)
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.
- Root Check: Verifies script is run with sudo privileges
-
Battery Detection:
- Uses
pmset -g battto detect battery presence - Identifies device as laptop or desktop
- Displays detection result
- Uses
-
Display Sleep Configuration:
- Sets 30 minutes on AC power (all devices)
- Sets 10 minutes on battery (laptops only)
-
Disk Sleep Configuration:
- Sets 60 minutes on AC power (all devices)
- Sets 30 minutes on battery (laptops only)
-
System Sleep Configuration:
- Desktops: Disables system sleep on AC power (sleep 0)
- Laptops: Sets 20 minutes on battery power
-
Hibernation Configuration:
- Desktops: Disables hibernation (hibernatemode 0)
- Laptops: Leaves default hibernation settings
- Verification: Reports success for each setting
The script exits immediately on any command failure due to set -euo pipefail.
- 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
- 0: Power settings configured successfully
-
1: Configuration failed:
- Script not run as root
- pmset command failed for any setting
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 ]
--------------------------------------------------------------
-
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
- View Script Source
- Scripts - Back to script index