Version 4 of alarm

Updated 2007-02-01 18:41:09

alarm is one of the many commands available in the Tclx extension.

     alarm seconds
          Instructs the system to send a SIGALRM signal in the speci-
          fied number of seconds.  This is a floating point number, so
          fractions of a section may be specified.  If seconds is 0.0,
          any previous alarm request is canceled.  Only one alarm at a
          time may be active; the command returns the number of sec-
          onds left in the previous alarm.  On systems without the
          setitimer system call, seconds is rounded up to an integer
          number of seconds.

          The alarm command is not available on Windows 95/NT.

Paul Walton Mach 28, 2006

Here's a simple alarm clock for Windows. I wrote it at 3 am when I really needed an alarm, so it was meant to just work and not be full of fancy features.

Requires Windows Media Player, or any other media player you can start from the command line. Perhaps someone can add an interface, use Snack instead of an external player, and add some other neat features.

Edit the globals WakeUpTime, MediaPlayer, and MediaFiles. Run with tclsh. Be sure to turn your speakers up.

 set WakeUpTime         {07:15:00 March 28, 2006}
 set MediaPlayer        [list {c:/program files/Windows Media Player/wmplayer}]
 lappend MediaFiles        {C:/Documents and Settings/Paul/My Documents/The Eagles - On the Border/04 - My Man.mp3}
 lappend MediaFiles        {C:/Documents and Settings/Paul/My Documents/The Eagles - On the Border/10 - The Best of My Love.mp3}
 lappend MediaFiles        {C:/Documents and Settings/Paul/My Documents/Hotel California/01 Eagles - Hotel California.mp3}

 # If the WakeUpTime is already passed, turn alarm initially off. If the WakeUpTime has yet to pass, turn the alarm on.
 if { [clock seconds] <= [clock scan $WakeUpTime] } {
        set Alarm on
        puts "Alarm is ON: $WakeUpTime"
 } else {
        set Alarm off
        puts "Alarm is OFF"
 }

 proc SoundAlarm {} {
        global Alarm
        global MediaPlayer
        global MediaFiles

        if { $Alarm } {
                puts "Sounding alarm!"
                set Alarm off
                eval [concat exec $MediaPlayer $MediaFiles &]
        }

        return
 }


 proc MonitorTime {} {
        global Alarm
        global WakeUpTime

        if { $Alarm  &&  [clock seconds] >= [clock scan $WakeUpTime] } {
                SoundAlarm
        }

        after 1000 MonitorTime
 }

 MonitorTime
 vwait forever

Category Command | Category TclX