Skip to content

Instantly share code, notes, and snippets.

@dchakro
Last active August 9, 2020 11:48
Show Gist options
  • Save dchakro/a9f41c834beda1cd4c092bd11b53ee98 to your computer and use it in GitHub Desktop.
Save dchakro/a9f41c834beda1cd4c092bd11b53ee98 to your computer and use it in GitHub Desktop.
Bash script to change hibernate mode on my macbook.
#!/usr/bin/env sh
# This script requires ripgrep. https://github.com/BurntSushi/ripgrep
# The script should also work wit grep.
# Just find and replace 'rg' with 'grep'
RED='\033[91m'
GREEN='\033[32m'
YELLOW='\033[93m'
CYAN='\033[96m'
NC='\033[0m'
printf '
Set system hibernate mode
1. RAM only
2. BatterySaver
3. Macbook default
4. Display status: ';
read var;
if [ "$var" -eq "1" ]; then
sudo -k pmset hibernatemode 0 ; sudo -K
echo "${RED}RAM only.${NC} Drains battery!!"
echo "check that it says ${CYAN}0${NC} below."
pmset -g | rg "hibernatemode"
fi
if [ "$var" -eq "2" ]; then
sudo -k pmset hibernatemode 25 ; sudo -K
echo "${GREEN}BatterySaver.${NC} Writes to hard disk!!"
echo "check that it says ${CYAN}25${NC} below."
pmset -g | rg "hibernatemode"
fi
if [ "$var" -eq "3" ]; then
sudo -k pmset hibernatemode 3 ; sudo -K
echo "${YELLOW}This is a half-assed hibernate!${NC} Writes to disk but also keeps the RAM powered!"
echo "check that it says ${CYAN}3${NC} below."
pmset -g | rg "hibernatemode"
fi
if [ "$var" -eq "4" ]; then
echo "\nCheck status below.\n\n0=${RED}RAM only${NC}\n3=${YELLOW}Half-assed${NC}\n25=${GREEN}Battery Saver${NC}\n"
pmset -g | rg "hibernatemode"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment