Safe Sleep

In the recent OS X 10.4.3, it is possible to “suspend” my powerbook into hibernate mode that does not use any power (see Andrew’s Blog). I write this simple script “sleepmode” to make life slightly easier with this feature.

#!/bin/sh
case ”$1” in
  deep)
    sudo pmset -a hibernatemode 1
  ;;
  safe)
    sudo pmset -a hibernatemode 3
  ;;
  normal)
    sudo pmset -a hibernatemode 0
  ;;
  go)
    omode=”`pmset -g | grep hibernatemode | cut -f 2`”
    sudo pmset -a hibernatemode 1
    echo The system is going to the deep sleep in 3 seconds
    sleep 3
    osascript -e 'tell application "Finder" to sleep'
    sudo pmset -a hibernatemode $omode
    echo The system is back to it orginal sleep mode
  ;;
esac

case ”`pmset -g | grep hibernatemode | cut -f 2`” in
  0)
  echo System is in the Normal Sleep Mode
  ;;
  1)
  echo System is in the Deep Sleep Mode
  ;;
  3)
  echo System is in the Safe Sleep Mode
  ;;
esac

3 Responses to “Safe Sleep”

  1. John Spencer Says:

    Could you please explain how a regular user could get this to work for her/him.

  2. orcas Says:

    This script is meat to use under terminal.app. Open a text editor, copy and past the script to the text editor and save it at some directory, e.g., /usr/local/bin/. I save the file with the name “sleepmode”. After saving the file, you need to open a terminal to change the permission of the file to executable by using the command “chmod u+x /usr/local/bin/sleepmode” under the terminal prompt. Then, you can switch the sleepmode by “sleepmode safe”, “sleepmode normal”, “sleepmode deep”. Or, you can go the deep sleep immediately by “sleepmode go”. This might seem complicated for people who don’t use unix shell. Well, I bet there will be a GUI control for changing sleep mode very soon.

  3. Jack Says:

    doesn’t work : “cannot execute binary file”

Leave a Reply