Skip to content

Instantly share code, notes, and snippets.

@ivan-leschinsky
Created August 7, 2017 21:32
Show Gist options
  • Select an option

  • Save ivan-leschinsky/2f0ed7798ef7a9299798ee7bf0ab7630 to your computer and use it in GitHub Desktop.

Select an option

Save ivan-leschinsky/2f0ed7798ef7a9299798ee7bf0ab7630 to your computer and use it in GitHub Desktop.
Functions for sleep mac in time
# Schedule sleep in X minutes, use like: sleepin 60
function sleepin() {
local minutes=$1
local datetime=`date --date "now + ${minutes} minutes" +"%m/%d/%y %H:%M:%S"`
echo "Will sleep on ${datetime}"
sudo pmset schedule sleep "$datetime"
}
# Cancels all sleep
function sleepstop() {
NUM_OF_SLEEPS=$(pmset -g sched | wc -l)
if [[ $NUM_OF_SLEEPS -gt 0 ]]; then
# The first line of output is a header, ignore it.
NUM_OF_SLEEPS=$(expr $NUM_OF_SLEEPS - 1)
seq $NUM_OF_SLEEPS | xargs -Iz sudo pmset schedule cancel 0
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment