Streamline Your MacBook’s Power Management with a Bash Script

Managing power settings on a MacBook can often feel cumbersome, especially for those who frequently switch between power sources. Recognizing the need for a more efficient method, I developed a Bash script to simplify the process, enabling quick toggling between “Normal” and “Never Sleep” modes depending on your current needs.

This script leverages the pmset command, a robust macOS tool for adjusting power settings. With it, you can effortlessly switch power schemes—saving time and avoiding manual adjustments through System Preferences.

One caveat is the necessity for administrative rights to execute the script, as it modifies system-wide settings. Thus, running it with sudo is essential for applying the changes successfully.

Despite this requirement, the script offers a convenient solution for managing your MacBook’s energy use, proving invaluable in various scenarios, such as prolonged work sessions or when ensuring uninterrupted downloads.

I’ve found this script to significantly enhance my workflow, offering a blend of convenience and flexibility previously unattainable with default power management options. I highly recommend trying it to see the difference it can make. Feedback and suggestions are always welcome for further refinements!

Here’s the script for those interested:

#!/bin/bash

###########################
# MacBook Power Management Script
#
# Simplifies toggling between power settings.
#
# Usage:
#   sudo bash script-name.sh
#
###########################

echo "Power Management Options"
echo "1. Normal"
echo "2. Never"
echo "3. Quit"
echo -n "Select an option: "
read option

case $option in
    1) 
        # Normal settings
        pmset -b displaysleep 2 # Battery: Display off after 2 mins
        pmset -c displaysleep 10 # Charger: Display off after 10 mins
        pmset -a sleep 20 # Both: Sleep after 20 mins
        ;;
    2) 
        # Never settings
        pmset -a displaysleep 0 # Display never sleeps
        pmset -a sleep 0 # System never sleeps
        ;;
    3) 
        # Quit
        exit
        ;;
    *)
        echo "Invalid option"
        ;;
esac