Skip to content

Instantly share code, notes, and snippets.

@losipiuk
Last active November 25, 2021 16:32
Show Gist options
  • Save losipiuk/93604352b2c2377a88404175a145f3a5 to your computer and use it in GitHub Desktop.
Save losipiuk/93604352b2c2377a88404175a145f3a5 to your computer and use it in GitHub Desktop.
timeout_lock
#/bin/env bash
if ! which say >/dev/null; then
echo "say command not found"
echo "you can install it using:"
echo " brew install espeak"
exit 1
fi
if [[ $# < 1 ]];then
echo "Usage: timeout_lock <timeout_in_seconds> [ <warning_period_in_seconds>]"
exit 2
fi
timeout=${1}
warning_period=${2:-300}
cur_time() {
date "+%s"
}
start_time=$(cur_time)
timeout_time=$[$(cur_time) + timeout]
sleep_time=10
while (( $(cur_time) < ${timeout_time} ));do
remaining=$[timeout_time - $(cur_time)]
echo "remaining: ${remaining}"
echo ${warning_period}
locale
if (( ${remaining} < ${warning_period} )); then
echo "${remaining} seconds left" | say
fi
sleep $((remaining < sleep_time ? remaining : sleep_time));
done
echo "locking"
pmset displaysleepnow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment