Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function quit()
- {
- say "$1"
- kill $dialog_pid
- exit "$2"
- }
- function say()
- {
- espeak -v english "$1" &
- }
- function enter()
- {
- input_time=$(zenity --entry --title="Remit" --text="Enter time interval in minutes" --entry-text=30)
- if test "$?" -ne 0; then
- quit "Aborted!" 1
- fi
- }
- function display()
- {
- remaining_time_in_minutes=$1
- if test $remaining_time_in_minutes -le 99; then
- formated_number=$(printf "%02d" $remaining_time_in_minutes)
- image_file_url="$image_directory_url/purple/$formated_number.png"
- yad --notification --image="$image_file_url" --timeout=60
- else
- number_of_hours=$((remaining_time_in_minutes / 60))
- remainder_in_minutes=$((remaining_time_in_minutes % 60))
- number_of_tens_of_minutes=$((remainder_in_minutes / 10))
- image_file_url="$image_directory_url/blue/$number_of_hours$number_of_tens_of_minutes.png"
- yad --notification --image="$image_file_url" --timeout=60
- fi
- }
- function announce()
- {
- remaining_time_in_minutes=$1
- number_of_hours=$((remaining_time_in_minutes / 60))
- number_of_minutes=$((remaining_time_in_minutes % 60))
- case $number_of_hours in
- 0)
- hour_word=""
- number_of_hours=""
- ;;
- 1)
- hour_word="hour"
- ;;
- *)
- hour_word="hours"
- esac
- case $number_of_minutes in
- 0)
- minute_word=""
- number_of_minutes=""
- ;;
- 1)
- minute_word="minute"
- ;;
- *)
- minute_word="minutes"
- esac
- say "$number_of_hours $hour_word $number_of_minutes $minute_word left"
- }
- image_directory_url="/home/skab/Data/izobrazheniya/sortirovannyye/kompyuter/znachki/tsyfry"
- enter
- until [[ $input_time =~ ^[0-9]+$ ]]; do
- say "Wrong input format"
- enter
- done
- announce "$input_time"
- announcement_time=$((input_time * 2 / 3))
- current_time=$input_time
- zenity --error --title="Remit" --text="Stop the timer" &
- dialog_pid=$!
- dialog_flag=$(wmctrl -l | grep "Remit")
- until test "$dialog_flag"; do
- dialog_flag=$(wmctrl -l | grep "Remit")
- done
- wmctrl -r "Remit" -t 2
- while test "$current_time" -gt 0; do
- if ! kill -0 $dialog_pid; then
- quit "Aborted" 1
- fi
- if test $current_time -eq $announcement_time; then
- announcement_time=$((announcement_time * 2 / 3))
- announce $current_time &
- fi
- display $current_time
- current_time=$((current_time - 1))
- done
- quit "Time's up!" 0
Add Comment
Please, Sign In to add comment