Something went wrong. Try again.
Mirroring: https://github.com/MunifTanjim/scripts.sh
Something went wrong. Try again.
scripts.sh schedule-sleep
620 B · 32 lines
at main
123456789101112131415161718192021222324252627282930313233#!/usr/bin/env bash
declare -r id="muniftanjim.sleep-timer"
function list() { pmset -g sched | tail -n +2 | grep "${id}" || true}
function abort() { declare entry="$(list | head -1)" while test -n "${entry}"; do sudo pmset schedule cancel "$(echo ${entry} | awk '{ print $1 }' | grep -o '[[:digit:]]*')" entry="$(list | head -1)" done}
function add() { declare minutes="${1}" declare datetime=$(/bin/date -v+${minutes}M +"%m/%d/%y %H:%M:%S") sudo pmset schedule sleep "${datetime}" "${id}"}
case "${1}" in abort) abort;; list) list;; *) abort add "${1}" ;;esac