PDA

View Full Version : safesleep (bash shell script) for unibody macbook



StevenSiew
14th March 2009, 09:41 PM
Here is a bash shell script written for unibody macbook and macbookpro

Step 1. Open terminal app
Step 2. Create a file called "safesleep" using the vi editor.

Contents of file "safesleep"
---- file:safesleep -----
#!/bin/bash

command=$1

if [ "X$command" == "Xstatus" ]; then
echo "Displaying the current safesleep status"
pmset -g | grep hibernatemode | cut -c2-
elif [ "X$command" == "Xon" ]; then
echo "Turning safesleep on"
sudo pmset -a hibernatemode 3
elif [ "X$command" == "Xoff" ]; then
echo "Turning safesleep off"
sudo pmset -a hibernatemode 0
elif [ "X$command" == "Xdeepsleep" ]; then
echo "Set to hibernate (aka deepsleep)"
sudo pmset -a hibernatemode 1
else
echo "USAGE: safesleep [on|off|deepsleep|status]"
echo
echo -n "Current Status: "
pmset -g | grep hibernatemode | cut -c2-
echo
echo "0 - Old style sleep mode, with RAM powered on while sleeping,"
echo " safe sleep disabled, and super-fast wake."
echo "1 - Hibernation mode, with RAM contents written to disk, system"
echo " totally shut down while sleeping, and slower wake up, due"
echo " to reading the contents of RAM off the hard drive."
echo "3 - The default mode on machines introduced since about Oct 2005."
echo " RAM is powered on while sleeping, but RAM contents are also "
echo " written to disk before sleeping. In the event of total power"
echo " loss, the system enters hibernation mode automatically."
echo "5 - This is the same as mode 1, but its for those using secure"
echo " virtual memory (in System Preferences -> Security)."
echo "7 - This is the same as mode 3, but its for those using secure"
echo " virtual memory."
echo
fi
---- endfile: safesleep -----

step 3. on bash execute command "chmod u+x safesleep"

step 4. safesleep is ready to use


Sample Usage
=========

EXAMPLE 1: To set macbook to sleep only and not save Memory to Harddisk)
$ ./safesleep off
Turning safesleep off
Password:

$./safesleep status
Displaying the current safesleep status
hibernatemode 0

$ ./safesleep
USAGE: safesleep [on|off|deepsleep|status]

Current Status: hibernatemode 0

0 - Old style sleep mode, with RAM powered on while sleeping,
safe sleep disabled, and super-fast wake.
1 - Hibernation mode, with RAM contents written to disk, system
totally shut down while sleeping, and slower wake up, due
to reading the contents of RAM off the hard drive.
3 - The default mode on machines introduced since about Oct 2005.
RAM is powered on while sleeping, but RAM contents are also
written to disk before sleeping. In the event of total power
loss, the system enters hibernation mode automatically.
5 - This is the same as mode 1, but its for those using secure
virtual memory (in System Preferences -> Security).
7 - This is the same as mode 3, but its for those using secure
virtual memory.


I hope this is of use to someone out there.

Steven Siew