Mint Serena 64 bit using the Mate desktop environment. Most of the following scripts will run on this machine, although some have only been tested with the Gnome desktop. Extra software requirements can be met by the Ubuntu and safe PPA repositories. Scripts may be re-written or added to from time to time, the date serves as the version number. Syntax highlighting on these pages is provided by GVim's "Convert to HTML" option.

Timer Mk3


#!/bin/bash
# Filename: progbar-timer.sh
# Version.: 19042017
# Author..: robz
# What another one!
# Improved from the "Egg Timer" script, a countdown timer with progress bar.
# This one has an indication of time remaining provided by Zenity's progress
# bar function. You'll need to choose a sound file below and maybe fiddle with
# the vector_tl function x&y coordinates.

vector_tl ()                                              # Dialog to top left.
{
x="541"; y="315"
until [ "$x" -lt "0" ]; do
    wmctrl -r "Egg Timer Mk3" -e 0,"$x","$y",210,129
    ((x-=30)); ((y-=18))
done
}

count=$(zenity --title "Egg Timer Mk3" --text "Decimals allowed Min/Hrs"\
    --entry-text "eg. 10s or 5m or 2h" --entry)           # Input dialogue.
if [ $? = 1 ]; then exit $?; fi

# Determine number of seconds to count down from depending on input suffix.
case "${count: -1}" in
    "S" | "s" ) count=$(echo ${count%?}/1 | bc) ;;
    "M" | "m" ) count=$(echo ${count%?}*60/1 | bc) ;;
    "H" | "h" ) count=$(echo ${count%?}*3600/1 | bc) ;;
    *         ) zenity --error --text "<span color=\"red\"><b>\
    \nUse the form of 10s or 5m or 2h\nDecimals allowed Min/Hrs.</b></span>"
    sh -c "$0"                                            # On error restart.
    exit ;;
esac

(sleep 1 && vector_tl) &

start=$count                                              # Set a start point.

until [ "$count" -eq "0" ]; do                            # countdown loop.
    ((count-=1))                                          # Decrement seconds.
    percent=$((100*count/start))                          # Calc percentage.
    echo "#Time remaining:$(echo "obase=60;$count" | bc)" # Convert to H:M:S.
    echo $percent                                         # Outut for progbar.
    sleep 1
done | zenity --title "Egg Timer Mk3" --progress --percentage=0 --text=""\
    --auto-close                                          # Progbar/time left.

if [ $? = 1 ]; then exit $?; fi
zenity --info --title "Egg Timer Mk3" --text "## TIMES UP ##" &
play $HOME/Scripts/glass_ping.wav                         # Ping sound finish!
vector_tl
exit


No comments: