#!/bin/bash case "$1" in -f) sudo pmset -a hibernatemode 0 result=$? if [ $result -eq 0 ];then sudo rm /var/vm/sleepimage echo "Fast sleep enabled and sleep image removed" exit 0 else echo "Password incorrect or not entered?" exit 1 fi ;; -h) sudo pmset -a hibernatemode 1 result=$? if [ $result -eq 0 ];then echo "Hibernate enabled" exit 0 else echo "Password incorrect or not entered?" exit 1 fi ;; -s) sudo pmset -a hibernatemode 3 result=$? if [ $result -eq 0 ];then echo "Safe sleep enabled" exit 0 else echo "Password incorrect or not entered?" exit 1 fi ;; *) echo "Hibernate script by Franklin van Velthuizen" echo "usage: hibernate [-fhs]" echo "-f Enable fast sleep mode" echo "-h Enable hibernation mode" echo "-s Enable safe sleep mode (default on newer MacBook Pros)" echo "" currentmode=`pmset -g | grep hibernatemode` set -- junk $currentmode shift if [ -n "${2+x}" ]; then if [ $2 -eq 0 ]; then echo "Current mode: Fast sleep mode" else if [ $2 -eq 1 ]; then echo "Current mode: Hibernation mode" else if [ $2 -eq 3 ]; then echo "Current mode: Safe sleep mode" else echo "Current mode: unknown" fi fi fi else echo "Current mode: unknown" fi exit 1 ;; esac