Created
August 7, 2017 21:32
-
-
Save ivan-leschinsky/2f0ed7798ef7a9299798ee7bf0ab7630 to your computer and use it in GitHub Desktop.
Functions for sleep mac in time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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