Effortlessly Manage Your MacBook’s Power Settings with a Simple Bash Script
I was just looking for a way to quickly switch my power settings on my MacBook, especially when working on battery and needing to keep my computer awake for extended periods. As many MacBook users know, constantly toggling between power management modes can be a bit of a hassle, particularly if you’re someone who frequently switches from being plugged into relying solely on battery power. This is where I found a need for a more streamlined approach.
In search of a solution, I crafted a Bash script that provides a hassle-free method for switching between two power management schemes: “Normal” and “Never.” The “Normal” setting aligns with my everyday usage, allowing the computer to sleep after a certain period of inactivity, whereas the “Never” option keeps my MacBook awake indefinitely, which is perfect for those long stretches of work where you can’t afford the computer to sleep or start the screen saver.
The script utilizes the pmset
command, a powerful tool in macOS for managing power settings. By running this script, you can easily toggle between these two modes with just a simple command, saving you the time and effort of manually adjusting settings in the System Preferences every time your work situation changes.
However, it’s important to note that this script requires administrative privileges to execute. This is because changing power management settings affects the entire system, so running the script with sudo
is necessary to ensure it has the needed permissions.
Despite this need for elevated privileges, the script provides a straightforward and convenient way to manage your MacBook’s power settings. Whether you’re in a meeting, working on a long train journey, or just don’t want your MacBook to sleep while downloading large files, this script is an invaluable tool.
To conclude, this Bash script has been a game-changer in managing my MacBook’s power settings. It’s a simple yet effective solution for anyone looking for more flexibility in how their MacBook uses power, especially when switching between different working environments. I encourage you to try it out and see how much simpler it can make your workflow. And as always, I’m open to feedback and suggestions for further improvements!
#!/bin/bash ########################### # Script to quickly change # Power settings on my # Macbook Pro # # James Strickland # james@strickstuff.com # ########################### 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: Turn display off after 2 minutes pmset -c displaysleep 10 # Charger: Turn display off after 10 minutes pmset -a sleep 20 # Both: Start screen saver after 20 minutes ;; 2) # Never settings pmset -a displaysleep 0 # Never turn off display pmset -a sleep 0 # Never start screen saver ;; 3) # Quit exit ;; *) echo "Invalid option" ;; esac