[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: looking for a clock, minimum and can play sound



On Tue, 04 Jan 2011 10:02:13 -0600, Hugo Vanwoerkom wrote:

(sorry for resurrecting this thread. I know is a bit old but I remembered 
the subject and thought the additional information could help the OP)

> Camaleón wrote:
>> On Tue, 04 Jan 2011 20:06:30 +0800, Zhang Weiwu wrote:
>> 
>>> Hello. I am looking for an count-down clock. Features are:
>> 
>> (...)
>> 
>> If you find no aplication that suits your needs, may I suggest a "do-
>> it-yourself" work? :-)
>> 
>> Dialog (command line ncurses scripting) and xdialog (GUI) can help you
>> here. It's very easy to use and just basic bash programming skills
>> needed.
>> 
>> Some tutotials with usage samples:
>> 
>> 
> If you get the source of dialog then you will find plenty of examples in
> the 'samples' dir.
> 
> Funny that you mentioned 'dialog': I just had a run-in with it. I wrote
> an app. in 2005 to use the '--form' option of it to fill out a form and
> pass the data to a daemon. Come to find out that my dialog script no
> longer worked: I got a -1 rc and the message  'Expected 8 parameters and
> found only 3'. That message was not very helpful so I got the source and
> modified 'dialog.c' to show *what* parameters it found. Turned out that
> dialog got tripped up by blanks in the form labels. But how come it ever
> worked?

Yep, I also have some scripts that used the ncurses "dialog" and you can 
expect some changes between versions (some bugs are fixed and you have to 
adjust your old code to get the same job done) :-)

Anyway, I've been recently working on a "enhanced" version of one of that 
scripts (now using "zenity" instead "dialog") and had to add kinda 
count-down to monitor the time a job gets done. I put here the code excerpt 
(is a very short piece of text) just in case the OP is still in the need of 
a simple counter (I guess it can be easily adapted to be run with "dialog"):


#!/bin/sh

# A simple count-down with progress bar
# that plays a sound alert once it's over

# Countdown start time (in seconds)
timer=30

# Sound file to play
sound="/usr/share/sounds/ekiga/voicemail.wav"

pbar=0
factor=$(echo "scale=2; 100/$timer" | bc)

(
for (( i=$timer; i>=0; i--)); do
echo $pbar;
echo "#Countdown: $timer seconds left"; timer=$((timer-1)); pbar=$(echo "scale=2; $pbar+$factor" | bc); sleep 1;
done;
aplay $sound 2>&1
) | 
	zenity \
	--progress \
	--auto-close \
	--title="Countdown" \
	--text="Countdown: $timer seconds left"

if [ $? = 1 ]; then exit; fi
exit


Greetings,

-- 
Camaleón


Reply to: