Last active
November 25, 2021 16:32
-
-
Save losipiuk/93604352b2c2377a88404175a145f3a5 to your computer and use it in GitHub Desktop.
timeout_lock
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
#/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