2009/05/22

How to Program a Batch File Alarm Clock

I had lost my cell phone, and it was lunch time. I wanted to take a short nap, but I had no way wake myself up. It is a sad fact that when Windows XP was developed, they forgot to include a built in alarm clock. Here is a batch file solution to that problem that I whipped up.
CLS
@echo off
color f0
title Batch Alarm Clock
echo.
echo.
echo.
echo Use the 24 hour clock: example 15:00 for 3:00PM
echo.
set /p a=Set Alarm:
CLS
echo.
echo.
echo Alarm is set for %a%.
echo.
echo You may minimize this window.

REM #### ALARM LOGIC ####
REM alarm will only sound for one minute.

:top
if %time:~0,5% == %a% echo ALARM!!! Close this window to stop.
goto top

Copy this code into a text file and name it Alarm.bat

The code is pretty simple to follow. The important parts are the set /p command where I gather the desired time and then the if statement at the bottom. The :~0,5% part of the time variable means that only a piece of that variable is being used. I don't care to match up the exact time down to the millisecond. The funny looking symbols that are being echoed later on that same line are actually CTRL+G symbols. They caused the computers internal alarm to beep for the entire minute that matches with the time you enter.

It might be ugly, but it works great. I was able to get that nap, and the alarm woke me up just fine!

0 comments:



ScriptingMadness.Blogspot.com © 2009 || Privacy Policy