Created
April 27, 2016 08:18
-
-
Save fatso83/f66cc30461a59b1ed590265ba66188bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Utility to force your mac immediately into hibernation mode/suspend to disk, | |
# thus conserving battery considerably (at the cost of slower startup) | |
# @date 2012-02-10 | |
# @author Carl-Erik Kopseng. Contact at oligofren.wordpress.com | |
# must be run as root by using sudo or to avoid entering the password, change the pmset | |
# executable settings by entering | |
# sudo chmod +s /usr/bin/pmset | |
# sudo chmod +s /sbin/shutdown | |
MODE_BACKUP=/tmp/hibernate_mode.bak | |
SUSPEND_TO_DISK=25 #see man pmset | |
display_settings() { | |
echo "Current settings: " $(pmset -g | grep hibernatemode) | |
} | |
save_settings() { | |
echo "saving settings" | |
pmset -g | grep hibernatemode | awk '{print $2}' > $MODE_BACKUP | |
} | |
restore_settings() { | |
echo "restoring settings" | |
pmset -a hibernatemode $(cat $MODE_BACKUP) | |
} | |
set_only_disk_hibernate() { | |
echo "changing settings to only suspend to disk (slow, but does not use battery)" | |
pmset -a hibernatemode $SUSPEND_TO_DISK | |
} | |
hibernate() { | |
echo "going into hibernation" | |
shutdown -s now | |
} | |
save_settings | |
set_only_disk_hibernate && hibernate | |
restore_settings |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment