@carlos: Yes, in this case substring extractions are simpler than array elements management...
: I edited the code below, so now it includes several options that may be selected via parameters. For details, type: CLOCK /?
: Oct/30/2013 - The code below includes alarm and timer, and a preliminary version of calendar.
: Nov-02-2013 - First complete version, it features the calendar fully functional and two new small sizes. I also eliminated the /W (week of day) switch, so it always show the weekday.
Note that if several switchs are given, they must be included precisely in the order show.
Code: Select all
@echo off
if "%~1" equ "alarmOff" goto alarmOff
setlocal DisableDelayedExpansion
set "bang=!"
setlocal EnableDelayedExpansion
::batch clock
::code author: carlos
::skin author: mxpower
::the clock automatically updates the display
::rem many changes
::rem updated 2013 october
::rem created 2008 november
rem Modified by Antonio Perez Ayala @ Oct/2013: display layouts, alarm/timer and calendar added
rem Nov/02/2013 - Version 1.0
if "%~1" neq "/?" goto begin
echo Clock.bat [/D] [/12] [/C] [/S:#] [/B:#] [/T:m[:s]] [/A:hh:mm]
echo/
echo /D Set blinking dots
echo /12 Set 12 hour format
echo /C Show calendar
echo /S:# Set small size, from 0 to 2 (cancel /Calendar)
echo /B:# Set brightness, from 0 to 3
echo /T:m[:s] Set timer in minutes and optional seconds
echo /A:hh:mm Set alarm time in 24 hour format (minutes in two digits)
echo/
echo You may run several instances of this program to set several timers or alarms
echo at different times; however, if more than one timer/alarm sounds at same time,
echo this program may fail.
echo/
echo To stop the buzzing alarm, press Enter.
goto :EOF
:begin
set "blink="
if /I "%~1" equ "/D" set "blink_dot=1" & set "blink=1" & shift
set "ampm1= "
set "ampm2= "
if /I "%~1" equ "/12" set "ampm2=M" & shift
if /I "%~1" equ "/C" set "cal=1" & shift
set cols=52
set lines1=21
set lines2=23
set stdFont=large
set "size="
set "param=%~1"
if /I "!param:~0,3!" equ "/S:" (
set "size=!param:~3!"
if "!size!" equ "0" (
set cols=15
set lines1=4
set lines2=4
set stdFont=thin
) else if "!size!" equ "1" (
set cols=21
set lines1=9
set lines2=9
) else (
set cols=29
)
set "cal="
shift
)
set lines=%lines1%
set level=3
set "param=%~1"
if /I "!param:~0,3!" equ "/B:" set "level=!param:~3!" & shift
set "bright=.°±²Û"
set back=!bright:~%level%,1!
set /A level+=1
set clock=!bright:~%level%,1!
for /L %%i in (1,1,48) do set "back=!back!%back%"
set "frame=Í"
for /L %%i in (1,1,48) do set "frame=!frame!%frame%"
if not defined cal (
set "fr=ÀÄÙ"
set w1=13
set w2=12
) else (
set "fr=ÀÄÁ"
set w1=1
set w2=24
)
set "space= "
for /L %%i in (1,1,30) do set "space=!space!%space%"
set "timer="
set "alarm="
set "alarmORtimer="
set "param=%~1"
if /I "!param:~0,3!" equ "/T:" (
for /F "tokens=1,2 delims=:" %%a in ("!param:~3!") do set /A "timerM=100+%%a, timerS=100+100%%b %% 100"
set "timer=!bang!timerM:~-2!bang!:!bang!timerS:~-2!bang!"
set blink_tmr=1
set blink=1
set alarmOrTimer=1
set "alarm= "
shift
)
set "param=%~1"
if /I "!param:~0,3!" equ "/A:" (
set "alarm=!param:~3!"
if "!alarm:~1,1!" equ ":" set "alarm=0!alarm!"
if not defined timer set "timer= "
set alarmOrTimer=1
)
if defined alarmORtimer (
if not defined cal (
set "fr=ô%fr%"
) else (
set "fr=ÃÂÅ%fr%"
)
set lines=%lines2%
)
if %stdFont% equ large (
Set "stdFont1=@@@ @ @@@@@@@ @@@@@@@@@@@@@@@@ "
Set "stdFont2=@ @ @ @ @@ @@ @ @@ @@ @ "
Set "stdFont3=@ @ @ @@@@@@@@@@@@@@@ @@@@@@@ "
Set "stdFont4=@ @ @ @ @ @ @@ @ @@ @ @ "
Set "stdFont5=@@@ @ @@@@@@ @@@@@@@ @@@@@@@ "
for /L %%i in (1,1,5) do set "stdFont%%i=!stdFont%%i:@=%clock%!"
) else (
Set "stdFont1=ÚÄ¿ ³ Ä¿ Ä¿³ ³ÚÄ ÚÄ Ä¿ÚÄ¿ÚÄ¿ "
Set "stdFont2=³ ³ ³ ÚÄÙ Ä´ÀÄ´ÀÄ¿ÃÄ¿ ³ÃÄ´ÀÄ´ "
Set "stdFont3=ÀÄÙ ³ ÀÄ ÄÙ ³ ÄÙÀÄÙ ³ÀÄÙ ÄÙ "
set "clock=ø"
)
Set "small1= _ _ _ _ _ _ _ _ "
Set "small2=³ ³ ³ _³ _³³_³³_ ³_ ³³_³³_³"
Set "small3=³_³ ³ ³_ _³ ³ _³³_³ ³³_³ _³"
set "m=JanFebMarAprMayJunJulAugSepOctNovDec"
set "w=SunMonTueWedThuFriSat"
set /A "sun=0,mon=1,tue=2,wed=3,thu=4,fri=5,sat=6"
set /A "jan=1,feb=2,mar=3,apr=4,may=5,jun=6,jul=7,aug=8,sep=9,oct=10,nov=11,dec=12"
set lastDay=0
call :getDate
mode con cols=%cols% lines=%lines%
color 0A
:clock
call :getDate
set hourB=%hour%
if "%ampm2%" equ "M" (
set "ampm1=A"
if %hour% geq 12 set /A hour-=12 & set "ampm1=P"
if "!hour!" equ "0" set hour=12
)
set /A h1=10%hour%/10%%10,h2=hour%%10, m1=10%minute%/10%%10,m2=minute%%10, d1=10%day%/10%%10,d2=day%%10
if "%ampm2%" equ "M" if %h1% equ 0 set h1=10
set "font=stdFont"
for %%_ in (h1 h2 m1 m2 d1 d2) do (
if %%_ equ d1 set "font=small"
set /a "index=3*%%_"
for %%s in (!font!) do for %%# in (!index!) do for /L %%i in (1,1,5) do set "%%_%%i=!%%s%%i:~%%#,3!"
)
set /a "index=3*(month-1)"
Set mfp=!m:~%index%,3!
set /a "index=3*weekday"
Set wdp=!w:~%index%,3!
set "th1=%day%%month%%year%%hourB%%minute%"
if %hourB% lss 10 set hourB=0%hourB%
if "%alarm%" neq " " if "%alarm%" equ "%hourB%:%m1%%m2%" (
call :showClock "%clock%"
call :alarm
set "alarm= "
if "%timer%" equ " " (
set "alarmOrTimer="
set lines=%lines1%
mode con cols=%cols% lines=!lines!
set "fr=%fr:~3%"
)
call :showClock "%clock%"
)
:blink
if "%timer%" neq " " set /A timerS-=1 & if "!timerS!" equ "99" set /A timerM-=1, timerS=159
call :showClock "%clock%"
if "%timer%" neq " " if "%timerM%:%timerS%" equ "100:100" (
call :alarm
set "timer= "
set "blink_tmr="
if not defined blink_dot set "blink="
if "%alarm%" equ " " (
set "alarmOrTimer="
set lines=%lines1%
mode con cols=%cols% lines=!lines!
set "fr=%fr:~3%"
)
call :showClock "%clock%"
)
:upd
ping -n 2 localhost >nul
if "%timer%" neq " " set /A timerS-=1 & if "!timerS!" equ "99" set /A timerM-=1, timerS=159
if defined blink_dot (call :showClock " ") else if defined blink_tmr call :showClock "%clock%"
if "%timer%" neq " " if "%timerM%:%timerS%" equ "100:100" (
call :alarm
set "timer= "
set "blink_tmr="
if not defined blink_dot set "blink="
if "%alarm%" equ " " (
set "alarmOrTimer="
set lines=%lines1%
mode con cols=%cols% lines=!lines!
set "fr=%fr:~3%"
)
call :showClock "%clock%"
)
ping -n 2 localhost >nul
call :getDate
set "th2=%day%%month%%year%%hour%%minute%"
if "%th1%" equ "%th2%" (
if not defined blink (
goto upd ) else (
goto blink ) ) else (
goto clock
)
:showClock dot
cls
if defined size goto smallSize
title %mfp%/%day% @ %hourB%:%m1%%m2%
echo/
echo É%frame:~0,48%»
if not defined cal (
echo º%back:~0,20% MxPower %back:~0,19%º
echo º%back:~0,13%ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿%back:~0,12%º
echo º%back:~0,13%³ ³%back:~0,12%º
echo º%back:~0,13%³ %h11% %h21% %m11% %m21% ³%back:~0,12%º
echo º%back:~0,13%³ %h12% %h22% %~1 %m12% %m22% %ampm1% ³%back:~0,12%º
echo º%back:~0,13%³ %h13% %h23% %m13% %m23% ³%back:~0,12%º
echo º%back:~0,13%³ %h14% %h24% %~1 %m14% %m24% %ampm2% ³%back:~0,12%º
echo º%back:~0,13%³ %h15% %h25% %m15% %m25% ³%back:~0,12%º
echo º%back:~0,13%³ ³%back:~0,12%º
echo º%back:~0,13%%fr:~0,1%ÄÄÄÄÄÄÄÄÄÄ%fr:~1,1%ÄÄÄÄÄÄÄÄÄÄ%fr:~2,1%%back:~0,12%º
) else (
echo º%back:~0,8% MxPower %back:~0,12% %mfp% - %year% %back:~0,7%º
echo º%back:~0,1%ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿%back:~0,1%º
echo º%back:~0,1%³ ³ Su Mo Tu We Th Fr Sa ³%back:~0,1%º
echo º%back:~0,1%³ %h11% %h21% %m11% %m21% ³%cal:~0,21% ³%back:~0,1%º
echo º%back:~0,1%³ %h12% %h22% %~1 %m12% %m22% %ampm1% ³%cal:~21,21% ³%back:~0,1%º
echo º%back:~0,1%³ %h13% %h23% %m13% %m23% ³%cal:~42,21% ³%back:~0,1%º
echo º%back:~0,1%³ %h14% %h24% %~1 %m14% %m24% %ampm2% ³%cal:~63,21% ³%back:~0,1%º
echo º%back:~0,1%³ %h15% %h25% %m15% %m25% ³%cal:~84,21% ³%back:~0,1%º
echo º%back:~0,1%³ ³%cal:~105,21% ³%back:~0,1%º
echo º%back:~0,1%%fr:~0,1%ÄÄÄÄÄÄÄÄÄÄ%fr:~1,1%ÄÄÄÄÄÄÄÄÄÄ%fr:~2,1%ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ%back:~0,1%º
)
if defined alarmORtimer (
echo º!back:~0,%w1%!³ Tr %timer% ³ Al %alarm% ³!back:~0,%w2%!º
echo º!back:~0,%w1%!ÀÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÙ!back:~0,%w2%!º
)
echo º%back:~0,48%º
echo º%back:~0,5%ÚÄÄÄ¿%back:~0,3%ÚÄÄÄ¿%back:~0,1% %d11%%d21% %back:~0,1%ÚÄÄÄÄ¿%back:~0,12%º
echo º%back:~0,5%³%wdp%³%back:~0,3%³%mfp%³%back:~0,1% %d12%%d22% %back:~0,1%³%year%³%back:~0,12%º
echo º%back:~0,5%ÀÄÄÄÙ%back:~0,3%ÀÄÄÄÙ%back:~0,1% %d13%%d23% %back:~0,1%ÀÄÄÄÄÙ%back:~0,12%º
echo º%back:~0,19% %back:~0,19%º
echo º%back:~0,48%º
echo ÈÍÍËÍÍÍÍÍË%frame:~0,30%ËÍÍÍÍÍËÍͼ
echo ÈÍÍÍÍͼ%space:~0,30%ÈÍÍÍÍͼ
exit /B
:smallSize
title %hourB%:%m1%%m2%
if %size% equ 0 (
echo %h11%%h21% %m11%%m21%%ampm1%
echo %h12%%h22%%~1%m12%%m22%
echo %h13%%h23%%~1%m13%%m23%%ampm2%
if not defined alarmOrTimer (
set /P "=-%mfp% %d1%%d2% %year%-" < NUL
) else (
set /P "=T%timer% A%alarm%" < NUL
)
) else if %size% equ 1 (
echo/
echo %h11% %h21% %m11% %m21%
echo %h12% %h22% %~1 %m12% %m22% %ampm1%
echo %h13% %h23% %m13% %m23%
echo %h14% %h24% %~1 %m14% %m24% %ampm2%
echo %h15% %h25% %m15% %m25%
set /P "=ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ %wdp%, %mfp% %d1%%d2% %year% " < NUL
if defined alarmOrTimer set /P "=Tr %timer% Al %alarm%" < NUL
) else (
echo/
echo É!frame:~0,25!»
echo º%back:~0,8% MxPower %back:~0,8%º
echo º!back:~0,1!ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿!back:~0,1!º
echo º!back:~0,1!³ ³!back:~0,1!º
echo º!back:~0,1!³ %h11% %h21% %m11% %m21% ³!back:~0,1!º
echo º!back:~0,1!³ %h12% %h22% %~1 %m12% %m22% %ampm1% ³!back:~0,1!º
echo º!back:~0,1!³ %h13% %h23% %m13% %m23% ³!back:~0,1!º
echo º!back:~0,1!³ %h14% %h24% %~1 %m14% %m24% %ampm2% ³!back:~0,1!º
echo º!back:~0,1!³ %h15% %h25% %m15% %m25% ³!back:~0,1!º
echo º!back:~0,1!³ ³!back:~0,1!º
echo º!back:~0,1!%fr:~0,1%ÄÄÄÄÄÄÄÄÄÄ%fr:~1,1%ÄÄÄÄÄÄÄÄÄÄ%fr:~2,1%!back:~0,1!º
if defined alarmORtimer (
echo º!back:~0,1!³ Tr %timer% ³ Al %alarm% ³!back:~0,1!º
echo º!back:~0,1!ÀÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÙ!back:~0,1!º
)
echo º!back:~0,25!º
echo º!back:~0,1!ÚÄÄÄ¿%back:~0,1% %d11%%d21% %back:~0,1%ÚÄÄÄÄ¿!back:~0,1!º
echo º!back:~0,1!³%mfp%³%back:~0,1% %d12%%d22% %back:~0,1%³%year%³!back:~0,1!º
echo º!back:~0,1!ÀÄÄÄÙ%back:~0,1% %d13%%d23% %back:~0,1%ÀÄÄÄÄÙ!back:~0,1!º
echo º!back:~0,7! !back:~0,8!º
echo º!back:~0,25!º
echo ÈÍÍËÍÍÍÍÍË!frame:~0,7!ËÍÍÍÍÍËÍͼ
echo ÈÍÍÍÍͼ!space:~0,7!ÈÍÍÍÍͼ
)
exit /B
:getDate
set "tf=~%random%"
type nul > "%temp%\%tf%.ddf"
makecab /d rptfilename="%temp%\%tf%.rpt" /d inffilename=nul /f "%temp%\%tf%.ddf" > nul
for /f "usebackq tokens=3-9 delims=: " %%a in ("%temp%\%tf%.rpt") do (
set /A "year=%%g,month=%%b,day=1%%c-100,weekday=%%a"
set /A "hour=1%%d-100,minute=1%%e-100,second=1%%f-100"
goto continue
)
:continue
del "%temp%\%tf%.ddf" "%temp%\%tf%.rpt" 2>nul
if not defined cal exit /B
if %day% equ %lastDay% exit /B
set /A "leap=year%%4, index=(month-1)*2, dow=weekday-day%%7+1"
if %dow% lss 0 set /A dow+=7
if %leap% neq 0 (
set "dpm=3128"
) else (
set "dpm=3129"
)
set "dpm=%dpm%31303130313130313031"
set dpm=!dpm:~%index%,2!
set "cal="
for /L %%i in (1,1,%dow%) do set "cal=!cal! "
for /L %%i in (1,1,%dpm%) do (
if %%i neq %day% (
set "n= %%i"
set "cal=!cal!!n:~-3!"
) else (
set "cal=!cal! ÛÛ"
)
)
for /L %%i in (1,1,15) do set "cal=!cal! "
set lastDay=%day%
exit /B
:alarm
del "%temp%\alarmOff.flg" 2> NUL
start "" /B "%~F0" alarmOff
:alarmOn
color CE
set /P "=" < NUL
ping -n 2 localhost >nul
color A
set /P "=" < NUL
ping -n 2 localhost >nul
if not exist "%temp%\alarmOff.flg" goto alarmOn
del "%temp%\alarmOff.flg"
exit /B
:alarmOff
set /P "="
echo off > "%temp%\alarmOff.flg"
exit