Skip to content

Instantly share code, notes, and snippets.

@shuujii
Created July 26, 2012 00:30
Show Gist options
  • Select an option

  • Save shuujii/3179564 to your computer and use it in GitHub Desktop.

Select an option

Save shuujii/3179564 to your computer and use it in GitHub Desktop.
Deep sleep and restore default hibernatemode on Mac
#!/bin/bash
PLIST=~/Library/LaunchAgents/my.resume.plist
RESUME=$(cd $(dirname $0); pwd)/mac-resume
machine_suspend() {
cat <<EOF > $PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>$(basename $PLIST .plist)</string>
<key>ProgramArguments</key>
<array>
<string>$RESUME</string>
</array>
<key>StartInterval</key>
<integer>60</integer>
</dict>
</plist>
EOF
[ -e $RESUME ] || ln -s mac-suspend $RESUME
sudo pmset -a hibernatemode 1
launchctl load $PLIST
pmset sleepnow
}
machine_resume() {
sudo pmset -a hibernatemode 3
launchctl unload $PLIST
rm -f $PLIST
}
case $(basename $0) in
mac-suspend) machine_suspend ;;
mac-resume) machine_resume ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment