Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

alarm batch file

Jan 1, 2010 11:25PM PST

Is it possible to create a batch file that will function as an alarm clock? Basically I'm asking if there's a command that functions as a timer. I think I could figure out the rest from there.

Thanks in advance!

Discussion is locked

- Collapse -
Well discussed.
Jan 2, 2010 1:21AM PST
- Collapse -
Here ya go...
Jun 8, 2012 7:57AM PDT

I wrote this before I found your post so it's a little more complicated than you need and would be tricky to adapt for purposes other than being an alarm clock.

If you want to adapt it to do something else when the alarm "goes off", look to this line:

@IF %var_alarm%==%var_time_current% SET var_alarm=Y

Replace the "SET var_alarm=Y" with some other command-prompt command you want executed.

************************************************************************

@ECHO OFF

@SET var_alarm=N
@SET /p var_alarm=Set alarm time in 24-hr time (HH:MM:SS); specify 'N' for NONE:

@SET var_change_bg=N
@SET var_change_fg=N
@IF %var_alarm%==N SET /p var_change_bg=Rotate background color? (Y/N):
@IF %var_alarm%==N SET /p var_change_fg=Rotate foreground color? (Y/N):

@MODE CON COLS=14 LINES=2

@SET var_time_current=%time:~0,8%
@SET var_time_last=%var_time_current%

:TOP

SET var_color_bg=%random%
SET /A var_color_bg=((%var_color_bg%*14)/32767)+1
SET var_color_fg=%random%
SET /A var_color_fg=((%var_color_fg%*14)/32767)+1

GOTO DEC2HEX

:RESUME

@SET var_time_current=%time:~0,8%

@IF NOT %var_time_current%==%var_time_last% CLS
@IF NOT %var_time_current%==%var_time_last% ECHO %var_time_current%
@IF NOT %var_time_current%==%var_time_last% COLOR %var_color_bg%%var_color_fg%
@IF NOT %var_time_current%==%var_time_last% SET var_time_last=%var_time_current%

@IF %var_alarm%==%var_time_current% SET var_alarm=Y
@IF %var_alarm%==Y SET var_change_bg=Y
@IF %var_alarm%==Y SET var_change_fg=Y

Goto TOP

GrinEC2HEX

if %var_color_bg%==10 SET var_color_bg=A
if %var_color_bg%==11 SET var_color_bg=B
if %var_color_bg%==12 SET var_color_bg=C
if %var_color_bg%==13 SET var_color_bg=D
if %var_color_bg%==14 SET var_color_bg=E
if %var_color_bg%==15 SET var_color_bg=F

if %var_change_bg%==N SET var_color_bg=0

if %var_color_fg%==10 SET var_color_fg=A
if %var_color_fg%==11 SET var_color_fg=B
if %var_color_fg%==12 SET var_color_fg=C
if %var_color_fg%==13 SET var_color_fg=D
if %var_color_fg%==14 SET var_color_fg=E
if %var_color_fg%==15 SET var_color_fg=F

if %var_change_fg%==N SET var_color_fg=7

GOTO RESUME