useful_scripts/sleepytime.sh

11 lines
710 B
Bash
Raw Normal View History

2023-03-24 14:40:17 -03:00
#!/bin/bash
usagemsg="usage: sleepytime.sh [time in seconds]\n%7ssleepytime.sh resume\n\nrequires read/write \
access to /tmp\nmake sure you only have one video player open or only the first one will be paused!\n"
pid=$(ps -aux | awk '{print $11" "$2}' | grep -m 1 "^mpv\|^vlc" | grep -o "[0-9]*")
printf "%d" "${pid}" > /tmp/sleepytime_pid
[ "$1" == "resume" ] && kill -SIGCONT $(cat /tmp/sleepytime_pid) && rm /tmp/sleepytime_pid && exit 0
printf "%d" "$1" 1>/dev/null 2>&1; [ "${?}" != 0 ] && printf "error: not a number\n${usagemsg}" && exit 2
sleepytime="${1:-1800}"
target_time=$(expr $(date +%s) + "${sleepytime}" );
while [ $(date +%s) -le "${target_time}" ]; do sleep 10; done; kill -SIGTSTP "${pid}"