假设您有一个需要很长时间才能完成的 TCL 过程,并且您需要在 TCL 过程结束时发出唤醒电话,以便您知道何时查看结果。
使用 tcl 代码将自己从深度睡眠中唤醒的好方法是什么......比如说你躺在沙发上,锯原木,你需要 tcl 程序的震动才能让你在完成处理时醒来?
例:
tcl_proc_that_takes_hours_to_complete
ring_alarm_bell_to_inform_user_that_proc_is_done
我想到了:
proc ring_alarm_bell_to_inform_user_that_proc_is_done {}
puts "a"
}
但不知何故,我认为它不够烦人,不足以用于此目的......
这是我的解决方案:
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
}
}
}
我非常喜欢在任务完成时使用口头通知;人们通常非常善于注意这一点,而不仅仅是一些随机的哔哔声。在macOS上,我使用这个:
proc say {something} {
# This is a trivial wrapper
exec say $something
}
say "All done now"
您有各种Linux选项,其中一些从Tcl的角度来看与上述选项非常相似,而Windows的其他选项都可以使用exec
调用,例如:
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"
您也可以使用 Snack 包进行直接播放或合成,但是当您可以使用现有设施时,这需要做更多的工作。