1

let's say you have a TCL procedure that takes an extremely long time to complete, and you need a wake up call at the end of the tcl procedure so that you know when to look at the results.

What's a good way to wake yourself up from a deep sleep using tcl code... like say you are lying on the couch, sawing logs, and you need a jolt from your tcl program to get you woken up when its done processing?

Example:

tcl_proc_that_takes_hours_to_complete
ring_alarm_bell_to_inform_user_that_proc_is_done

I thought about:

proc ring_alarm_bell_to_inform_user_that_proc_is_done {} 
    puts "\a"
}

but somehow, i think its not annoying enough to be useful for this purpose...

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
Pico99
  • 31
  • 1
  • 5

2 Answers2

0

Here's my solution:

proc wake_up_beep {} {
    set beep_on_end 1

    if {$beep_on_end} {
        puts "WHATEVER YOU WERE DOING IS FINISHED! (ctrl-C to exit)\a"
        while {1} {
            puts -nonewline "\a"
            after 1000
        }
    }
}
Pico99
  • 31
  • 1
  • 5
0

I quite like to use a spoken announcement on task completion; people are in general very good at paying attention to that, much more so than just some random bleep. On macOS, I use this:

proc say {something} {
    # This is a trivial wrapper
    exec say $something
}

say "All done now"

You have various options for Linux, some of which look very similar to the above from a Tcl perspective, and other options for Windows, all of which can be invoked using exec, e.g.:

proc say {something} {
    # This is a not-so trivial wrapper, and should be tested before production use
    exec PowerShell -Command [format {Add-Type –AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('%s');}
}
say "All done now"

You could also use the Snack package to do direct playback or synthesis, but that's a lot more work when there's existing facilities that you can use.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215