| Author |
Message |
jpeps
Joined: 31 May 2008 Posts: 2421
|
Posted: Thu 06 Jan 2011, 19:52 Post subject:
"tm" command line timer Subject description: runs in the background |
|
USAGE: tm [min]:[sec][sound]
or: tm [min]
examples "tm 20:5" (20 min, 5 sec)
"tm 30" (30 min)
"tm :5" (5 sec)
"tm :10 bark.au" (10 seconds, plays bark.au)
Comes with gong-burmese.wav, which it plays by default.
Main script:
| Code: |
#!/bin/sh
### Command line Timer jpeps 1/11
## Help
## Sound path is /usr/share/audio
if [ "$1" == "" -o "$1" == "-h" ]; then
echo "USAGE: [min]:[sec] [sound]"
echo "USAGE: [min]"
echo "sound path: /usr/share/audio"
exit
fi
dir="/usr/share/audio/"
## Set Sound
if [ "$2" ]; then
snd="$2"
else
snd="gong-burmese.wav"
fi
sep="$(echo ${1} | grep ":")"
min="$(echo ${1} | cut -d":" -f1)"
[ "$min" ] || min="0"
sec="$(echo ${1} | cut -d":" -f2)"
[ "$sec" ] || sec="0"
tmin="$((${min}*60 ))"
## Allow for entree without ":" for minutes
if [ "$sep" == "" ]; then
tsec="$((${1}*60))"
else
tsec="$((${tmin}+${sec}))"
fi
x="tsec"
n="0"
for ((i=0;i<=${x};i++)); do
n="$((${n} + 1))"
if [ "$n" == "${tsec}" ]; then
aplay ${dir}${snd} 2>/dev/null
fi
sleep 1
done
exit
|
| Description |
|

Download |
| Filename |
cli-timer.pet |
| Filesize |
39.26 KB |
| Downloaded |
277 Time(s) |
|
|
Back to top
|
|
 |
Lobster
Official Crustacean

Joined: 04 May 2005 Posts: 15109 Location: Paradox Realm
|
Posted: Fri 07 Jan 2011, 05:08 Post subject:
|
|
Very well done.
Timers can be most useful
You might be interested in this thread.
http://www.murga-linux.com/puppy/viewtopic.php?p=351139&search_id=704342068#351139
_________________ Puppy WIKI
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2421
|
Posted: Fri 07 Jan 2011, 13:02 Post subject:
|
|
Thanks...thought you might like the gong
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Mon 10 Jan 2011, 02:35 Post subject:
|
|
here is a little stopwatch snippet i wrote | Code: | #!/bin/ash
read -p "Enter to start"
while(true)do clear
read -t 1 -p "Enter to stop "${h}:${m}:$((s++)) && break
[ "$s" -gt 59 ] && m=$((m+1)) && s=0 && [ "$m" -gt 59 ] && h=$((h+1)) && m=0
done |
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 5244 Location: Valåmoen, Norway
|
Posted: Mon 10 Jan 2011, 09:12 Post subject:
|
|
_________________ Stardust resources
|
|
Back to top
|
|
 |
don570

Joined: 10 Mar 2010 Posts: 2473 Location: Ontario
|
Posted: Mon 10 Jan 2011, 19:48 Post subject:
gui version |
|
I made a GUI version of this program, simplifying it a great deal
but it gives a visual message and a nice sound.
I call it PmusicTimer. I believe that this is the
first time that Pmusic has been used as a simple timer.
However Pmusic can be used with Pschedule to delay the playing
of a playlist.
Pmusic has the benefit that mp3 files can be used and
nearly all Puppies have pmusic built-in.
There is a bug that I found with the GUI. Only short sounds can
be used... but that isn't much of a problem since it
is to used as a simple alarm timer.
Here it is . Feel free to change it any way you want.
A nice loud sound file is included.
http://www.datafilehost.com/download-26eb0ce4.html
_______________________________________________________
|
|
Back to top
|
|
 |
don570

Joined: 10 Mar 2010 Posts: 2473 Location: Ontario
|
Posted: Mon 10 Jan 2011, 19:51 Post subject:
PmusicTimer script |
|
Here's the script and pet package
http://www.datafilehost.com/download-26eb0ce4.html
| Code: | #! /bin/bash
export DIALOG="
<window title=\"Pmusic Timer\">
<vbox>
<pixmap><input file>/usr/share/images/document-open-recent.png</input></pixmap>
<text width-request=\"190\"> <label> \n
</label></text>
<hbox>
<text width-request=\"190\"> <label> Enter number of minutes</label></text>
<entry width-request=\"100\">
<variable>ENTRY</variable>
</entry>
</hbox>
<hbox>
<text width-request=\"190\"> <label> \n
</label></text>
</hbox>
<hbox>
<button ok></button>
<button cancel></button>
</hbox>
</vbox>
</window>"
I=$IFS; IFS=""
for STATEMENTS in $(gtkdialog3 --geometry=+200+100 --program DIALOG); do
eval $STATEMENTS
done
dir="/usr/share/audio/"
snd="clock.mp3"
min="$ENTRY"
tsec="$((${min}*60 ))"
x="tsec"
n="0"
for ((i=0;i<=${x};i++)); do
n="$((${n} + 1))"
if [ "$n" == "${tsec}" ]; then
pmusic -b ${dir}${snd} 2>/dev/null
yaf-splash -bg orange -fontsize x-large -text " $ENTRY minutes is up.
Timer has finished!!! " -close box &
fi
sleep 1
done
pmusic -s quit
exit |
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2421
|
Posted: Mon 10 Jan 2011, 23:17 Post subject:
Re: gui version |
|
| don570 wrote: |
There is a bug that I found with the GUI. Only short sounds can
be used... but that isn't much of a problem since it
is to used as a simple alarm timer.
|
You might put the player outside the loop.
| Code: |
mflag=''
for ((i=0;i<=${x};i++)); do
n="$((${n} + 1))"
if [ "$n" == "${tsec}" ]; then
mflag="1"
break
fi
sleep 1
done
[ "$mflag" ] && pmusic ${dir}${snd} 2>/dev/null
|
|
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 5244 Location: Valåmoen, Norway
|
Posted: Tue 11 Jan 2011, 06:31 Post subject:
|
|
don570
Really cool to see that you build a gui
Try to run pmusic as a standalone process:
| Code: | | pmusic -b ${dir}${snd} 2>/dev/null & |
Sigmund
_________________ Stardust resources
|
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 5244 Location: Valåmoen, Norway
|
Posted: Thu 13 Jan 2011, 12:30 Post subject:
|
|
pTiming
_________________ Stardust resources
|
|
Back to top
|
|
 |
don570

Joined: 10 Mar 2010 Posts: 2473 Location: Ontario
|
Posted: Sat 15 Jan 2011, 14:08 Post subject:
new countdown timer |
|
Here's the newest pet
http://www.datafilehost.com/download-e2c1fa85.html
I've given up trying to make pmusic into timer, especially
when I discovered that the current playlist vanishes after
running the timer, so I'll stick with aplay
Here's my most current try. It's only 25k uncompressed.
That's because I use 2barks.wav which is built into Puppy.
I've basically broken up the program into 2 parts.
One is called tm ------> the original cli program,
the other tmtimer ---> the GUI
They are stored in the same place, /usr/local/bin/
Here is the code for the GUI part
| Code: | #! /bin/bash
export DIALOG='
<vbox>
<hbox> <text> <label> \n
</label></text></hbox>
<hbox>
<text>
<label> Enter number of minutes</label>
</text>
<entry>
<variable>ENTRY</variable>
</entry>
</hbox>
<hbox> <text> <label> \n
</label></text></hbox>
<hbox>
<button>
<label>Start</label>
<input file>/usr/share/images/document-open-recent.png</input>
<action>echo You pressed the exit button</action>
<action type="exit">Exit by button</action>
</button>
<text> <label> " " </label></text>
</hbox>
<hbox> <text> <label> \n
</label></text></hbox>
</vbox>
'
I=$IFS; IFS=""
for STATEMENTS in $(gtkdialog3 --geometry=+200+100 --program DIALOG); do
eval $STATEMENTS
done
tm $ENTRY
exit |
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2421
|
Posted: Sat 15 Jan 2011, 17:27 Post subject:
|
|
Might as well allow seconds:
| Code: |
<label> Enter number of minutes:seconds</label>
|
You could also have an entry box for sound
|
|
Back to top
|
|
 |
don570

Joined: 10 Mar 2010 Posts: 2473 Location: Ontario
|
Posted: Wed 19 Jan 2011, 18:57 Post subject:
improved tm timer |
|
It wasn't too hard to include an option for selection of a sound file.
It just required a few extra lines of code. | Code: |
<frame Sound file>
<hbox>
<text>
<label> /root/puppy-reference/audio/</label>
</text>
<entry>
<default>2barks.wav</default>
<variable>SND</variable>
</entry>
</hbox>
</frame>
|
Here it is.
http://www.datafilehost.com/download-bb8e323d.html
This is as far as I can take this project. Someone else will have to take it
over and add more features. A tray app to tell the remaining time
would be nice.
______________________________________________
|
|
Back to top
|
|
 |
big_bass

Joined: 13 Aug 2007 Posts: 1736
|
Posted: Fri 21 Jan 2011, 11:31 Post subject:
|
|
Here's an easy function to add to the list of optional solutions
Joe
-------------------
cfajohnson
Shell programmer, author
http://www.unix.com/shell-programming-scripting/98889-display-runnning-countdown-bash-script.html
| Code: | countdown()
(
IFS=:
set -- $*
secs=$(( ${1#0} * 3600 + ${2#0} * 60 + ${3#0} ))
while [ $secs -gt 0 ]
do
sleep 1 &
printf "\r%02d:%02d:%02d" $((secs/3600)) $(( (secs/60)%60)) $((secs%60))
secs=$(( $secs - 1 ))
wait
done
echo
)
# format hours: minutes :seconds
countdown "00:02:00" |
_________________ slackware 14
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2421
|
Posted: Fri 21 Jan 2011, 15:02 Post subject:
|
|
| big_bass wrote: | Here's an easy function to add to the list of optional solutions
Joe
|
Running sleep in background with the wait command is clever.
edit: ran better with:
| Code: |
secs=$(( ${1:0} * 3600 + ${2:0} * 60 + ${3:0} ))
|
|
|
Back to top
|
|
 |
|