Skip to content

Instantly share code, notes, and snippets.

@mattward
Created March 21, 2016 09:30
Show Gist options
  • Save mattward/2299421e445a68a07f20 to your computer and use it in GitHub Desktop.
Save mattward/2299421e445a68a07f20 to your computer and use it in GitHub Desktop.
Set Macbook "deep sleep" threshold between Apple's default time (1 hr 10 mins) and a longer time (3 hrs)
#!/bin/bash
script_name=`basename $0`
function show_usage {
echo "Sets the time delay before the Mac goes into 'deep sleep'."
echo " Usage: $script_name time"
echo " Where time is 'default' or 'long'."
exit 1
}
# check number of arguments
if [[ $# != 1 ]]; then
show_usage
fi
if [[ "$1" == "default" ]]; then
delay_seconds=4200
fi
if [[ "$1" == "long" ]]; then
delay_seconds=10800
fi
# invalid argument
if [[ "$delay_seconds" == "" ]]; then
show_usage
fi
pmset -a standbydelay $delay_seconds
if [[ $? == 0 ]]; then
echo "Set sleep delay to $((delay_seconds/(60*60)))h (${delay_seconds}s)"
else
echo "Unable to set sleep delay"
fi
@mattward
Copy link
Author

This script is a quick and easy way to alter the "deep sleep" threshold (i.e. the time before Macbooks enter a hibernate to disk state). The problem with deep sleep is that it is damn slow to wake up (particularly with 16GB of RAM).

Set whatever "long" delay you want. I tried 24 hours and the battery drained too fast, so I'm currently trying 3 hours as a compromise between Apple's rather short 1:10 and the battery draining 24:00.

Pop it in $HOME/bin (assuming you have this on your $PATH) and use "sudo" to run it (pmset requires this) -- e.g. "sudo sleep-delay long".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment