I have found the following script online for a simple timer script:
Code:
#!/usr/bin/wish -f
set intime [lindex $argv 0]
set intimeI [expr $intime * 60]
proc countdown {seconds} {
init
countdown_kernel $seconds
}
proc countdown_kernel seconds {
hands $seconds
if !$seconds return
after 1000
[list countdown_kernel [incr seconds -1]]
}
proc draw_hand {angle decorations} {
eval .c create line $::size $::size [get_xy $angle] $decorations
}
proc end_coordinate difference {
set hand_length [expr $::size * .9]
return [expr $::size + $hand_length * $difference]
}
proc get_xy angle {
return
[list [end_coordinate [expr sin($angle)]] \
[end_coordinate [expr -cos($angle)]]]
}
proc hands seconds {
catch {.c delete withtag hands}
set twopi 6.283185
set seconds_angle [expr $seconds * $twopi / 60.]
draw_hand $seconds_angle "-width 1 -tags hands"
set minutes_angle [expr $seconds_angle / 60.]
draw_hand $minutes_angle \
"-width 3 -capstyle projecting -tags hands"
}
proc init {} {
catch {destroy .c}
set ::size 90
set full_diameter [expr 2 * $::size]
pack [canvas .c -width $full_diameter -height $full_diameter]
set border 2
set diameter [expr 2 * $::size - $border]
.c create oval $border $border \
$diameter $diameter \
-fill darkred -outline gold
}
proc helw {} {
wm title . "TIME IS UP!"
button .bHello -text "Times Up!" -command exit
pack .bHello
exec play ~/sounds/doh.wav &
}
countdown $intimeI
after [expr $intimeI * 1000] helw
# puts stdout "Time is $intimeI"
Questions:
a. I have just called it "Timer" I have chmod the script:
Code:
glenn@design:~/Desktop$ sudo chmod 775 Timer
glenn@design:~/Desktop$ ls -al Timer
-rwxrwxr-x 1 glenn glenn 1941 Oct 25 02:15 Timer
glenn@design:~/Desktop$
Is that correct?
b. How do I change the timer to run in seconds rather than minutes?
c. When I try to run the script, I get the following error:
Code:
glenn@design:~/Desktop$ sh Timer
Timer: 5: Timer: proc: not found
init: Need to be root
Timer: 7: Timer: countdown_kernel: not found
Timer: 8: Timer: Syntax error: "}" unexpected
glenn@design:~/Desktop$
I do't want to run the script as root.
Can someone please help.
Bookmarks