[code] Batch Clock Widget

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

[code] Batch Clock Widget

#1 Post by carlos » 25 Oct 2013 19:44

Hello. Today I read a post asking for a clock in batch. I remember one of my first codes in batch in 2008, when I fix some bugs and added some functionalitys in a batch clock of some user. Today I update all the code, keeping readibility and using a updated routine for get the time.

Keep in your desktop like a widget.

in this post:
clock:
Image

clock.cmd

Code: Select all

@echo off
setlocal enableextensions enabledelayedexpansion

::Batch clock
:: consolesoft.com/batch/?#clock
::Code author: Carlos Montiers Aguilera
::Last updated: 2015, 19 february: minor changes
::Updated: 2014, 31 march: minor changes
::Updated: 2013, 18 november: reduced cpu usage fixed
::Created: 2013, october
::
::the clock automatically updates the display
::note: only open 1 instance of this script
::else it may fail
::for use 24 hour clock set /a "format=24"
::for use 12 hour clock set /a "format=12"
set /a "format=12"
::
mode con cols=23 lines=10
color 0a

Set "diga=ÛÛÛ Û ÛÛÛÛÛÛÛ ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ"
Set "digb=Û Û Û   Û  ÛÛ ÛÛ  Û    ÛÛ ÛÛ Û"
Set "digc=Û Û Û ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ  ÛÛÛÛÛÛÛ"
Set "digd=Û Û Û Û    Û  Û  ÛÛ Û  ÛÛ Û  Û"
Set "dige=ÛÛÛ Û ÛÛÛÛÛÛ  ÛÛÛÛÛÛÛ  ÛÛÛÛÛÛÛ"
set "m=JanFebMarAprMayJunJulAugSepOctNovDec"
set "w=MonTueWedThuFriSatSun"

call :getdate.init
call :getdate

:clock
set "th1=%day%%month%%year%%hour%%minute%"
set "da=."
set "db=."
if 12 equ !format! (set "db=M"
set "da=A"
if 12 leq %hour% (set /a "hour-=12"
set "da=P"
)
if 0 equ !hour! set "hour=12"
)

set /a "h1=hour/10,h2=hour-10*h1"
set /a "m1=minute/10,m2=minute-10*m1"

for %%_ in (h1 h2 m1 m2) do (set /a "index=3*%%_"
for %%# in (!index!) do (
set "%%_a=!diga:~%%#,3!"
set "%%_b=!digb:~%%#,3!"
set "%%_c=!digc:~%%#,3!"
set "%%_d=!digd:~%%#,3!"
set "%%_e=!dige:~%%#,3!"
))

set /a "index=3*(month-1)"
Set "mfp=!m:~%index%,3!"
set /a "index=3*(weekday-1)"
Set "wdp=!w:~%index%,3!"
set "dfp=%day%"
if %dfp% lss 10 set "dfp= %dfp%"

cls
if 12 equ !format! (title %h1%%h2%:%m1%%m2% %da%%db%
) else title %h1%%h2%:%m1%%m2%
echo(
echo    %h1a% %h2a%   %m1a% %m2a%
echo    %h1b% %h2b%   %m1b% %m2b%
echo    %h1c% %h2c% %da% %m1c% %m2c%
echo    %h1d% %h2d% %db% %m1d% %m2d%
echo    %h1e% %h2e%   %m1e% %m2e%
echo(
echo    ÄÄÄÄÄÄÄÂÄÄÂÄÄÄÄÄÄ
echo      %wdp%  ³%dfp%³ %mfp%

:upd
call :getdate
set "th2=%day%%month%%year%%hour%%minute%"
if not "%th1%"=="%th2%" goto :clock
ping -l 0 -n 1 -w 500 1.0.0.0 >nul 2>&1
goto :upd

:getdate.init
set /a "jan=1,feb=2,mar=3,apr=4,may=5,jun=6,jul=7"
set /a "aug=8,sep=9,oct=10,nov=11,dec=12"
set /a "mon=1,tue=2,wed=3,thu=4,fri=5,sat=6,sun=7"
(echo .set infheader=""
echo .set infsectionorder=""
echo .set inffooter="%%2"
for /l %%# in (1,1,4) do echo .set inffooter%%#=""
echo .set cabinet="off"
echo .set compress="off"
echo .set donotcopyfiles="on"
echo .set rptfilename="nul"
) >"!temp!\~foo.ddf" 2>nul
set "random="
set "tf=!temp!\~%random%"
goto :eof

:getdate
makecab /d inffilename="!tf!" /f "!temp!\~foo.ddf" >nul 2>&1
for /f "usebackq tokens=1-7 delims=: " %%a in ("%tf%") 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")
del "%tf%" >nul 2>&1
goto :eof



other models from Aacini: http://www.dostips.com/forum/viewtopic.php?p=29424#p29424
Image
Last edited by carlos on 04 Apr 2015 14:05, edited 42 times in total.

Batch Artist
Posts: 22
Joined: 18 Oct 2013 05:28

Re: [code] Batch Clock Widget

#2 Post by Batch Artist » 25 Oct 2013 23:15

Pretty sweet and code works like a charm!
Well damn good job on the widget. It is really impressive!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: [code] Batch Clock Widget

#3 Post by foxidrive » 25 Oct 2013 23:48

It's a neat display carlos.

I added a 20 second ping command after the :upd label and would live with a 20 second accuracy, as it uses a fair whack of CPU etc when constantly checking date and time.

Code: Select all

:upd
ping -n 20 localhost >nul



Or it could check the minute counter of the %time% variable and only update via the :getdate routine every minute.

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: [code] Batch Clock Widget

#4 Post by carlos » 26 Oct 2013 01:21

@Batch Artist: thanks for the comments.
@foxidrive: thanks for the suggestion. I updated the code with a implementation of your idea.

Note: Updated again:
Posted updates that uses ping -n but after many tests I confirm that it is not safe, then I rollback with minor changes.

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: [code] Batch Clock Widget

#5 Post by Aacini » 26 Oct 2013 02:28

I like it! :D

I modified it a little in order to made it more compact.

Code: Select all

@echo off

::batch clock
::the clock automatically updates the display
::note: only open 1 instance of this script else it may fail
::for not show the week day change the variable show_week_day to 0
set "show_week_day=1"
::rem updated again in title section
::rem updated 2013 october
::rem created 2008 november

mode con cols=49 lines=16
color 0a

REM Aacini - Initialize array variables
setlocal EnableDelayedExpansion
set i=0
for %%d in (" _ #³ ³#³_³" "   # ³ # ³ " " _ # _³#³_ ") do (
   for /F "tokens=1-3 delims=#" %%a in (%%d) do (
      set "h1a[!i!]=%%a"
      set "h1b[!i!]=%%b"
      set "h1c[!i!]=%%c"
   )
   set /A i+=1
)
set i=0
for %%d in (" _ #³ ³#³_³" "   # ³ # ³ " " _ # _³#³_ " " _ # _³# _³" "   #³_³#  ³"
            " _ #³_ # _³" " _ #³_ #³_³" " _ #  ³#  ³" " _ #³_³#³_³" " _ #³_³# _³") do (
   for /F "tokens=1-3 delims=#" %%a in (%%d) do (
      set "h2a[!i!]=%%a"
      set "h2b[!i!]=%%b"
      set "h2c[!i!]=%%c"
   )
   set /A i+=1
)
set i=0
for %%d in (" _ #³ ³#³_³" "   # ³ # ³ " " _ # _³#³_ " " _ # _³# _³" "   #³_³#  ³" " _ #³_ # _³") do (
   for /F "tokens=1-3 delims=#" %%a in (%%d) do (
      set "m1a[!i!]=%%a"
      set "m1b[!i!]=%%b"
      set "m1c[!i!]=%%c"
   )
   set /A i+=1
)
set i=0
for %%d in (" _ #³ ³#³_³" "   # ³ # ³ " " _ # _³#³_ " " _ # _³# _³" "   #³_³#  ³"
            " _ #³_ # _³" " _ #³_ #³_³" " _ #  ³#  ³" " _ #³_³#³_³" " _ #³_³# _³") do (
   for /F "tokens=1-3 delims=#" %%a in (%%d) do (
      set "m2a[!i!]=%%a"
      set "m2b[!i!]=%%b"
      set "m2c[!i!]=%%c"
   )
   set /A i+=1
)
set i=0
for %%a in (" january  " " february " "  march   " "  april   " "   may    " "   june   "
            "   jule   " "  august  " "september " " october  " " november " " december ") do (
   set /A i+=1
   set "mfp[!i!]=%%~a"
)
set i=0
for %%a in (mon tue wed thu fri sat sun) do (
   set /A i+=1
   set "wdp[!i!]=%%a"
)
set i=0
for %%a in (jan feb mar apr may jun jul aug sep oct nov dec) do (
   set /A i+=1
   set %%a=!i!
)
set i=0
for %%a in (mon tue wed thu fri sat sun) do (
   set /A i+=1
   set %%a=!i!
)

:clock
cls
call :getdate
Set "str_h=%hour%"
Set "str_m=%minute%"

if %hour% lss 10 (Set "str_h=0%hour%"
set /a "h1=0,h2=%hour%"
) else set /a "h1=%hour:~0,1%,h2=%hour:~1,1%"

if %minute% lss 10 (Set "str_m=0%minute%"
set /a "m1=0,m2=%minute%"
) else set /a "m1=%minute:~0,1%,m2=%minute:~1,1%"

title %str_h%:%str_m%

for %%i in (1 2) do for /F "tokens=1,2" %%l in ("!h%%i! !m%%i!") do (
   for %%a in (a b c) do (
      set "h%%i%%a=!h%%i%%a[%%l]!"
      set "m%%i%%a=!m%%i%%a[%%m]!"
   )
)

set "dfp=%day%"
if %dfp% lss 10 set "dfp=0%dfp%"

set "mfp=!mfp[%month%]!"

set "wdp=!wdp[%weekday%]!"

echo.
echo  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo  º²²²²²²²²²²±ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿±²²²²²²²²²²±º
echo  º²MxPower²²±³ %h1a% %h2a%   %m1a% %m2a%  ³±²²²²²²²²²²±º
echo  º²²²²²²²²²²±³ %h1b% %h2b% . %m1b% %m2b%  ³±²²²²²²²²²²±º
echo  º²²²²²²²²²²±³ %h1c% %h2c% . %m1c% %m2c%  ³±²²²²²²²²²²±º
echo  º²²²²²²²²²²±³                    ³±²²²²²²²²²²±º
echo  º²²²²²²²²²²±ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ±²²²²²²²²²²±º
echo  º²²²²²²²²²²±±±±±±±±±±±±±±±±±±±±±±±±²²²²²²²²²²±º
if 1 equ %show_week_day% (
echo  º²²²²²°ÚÄÄÄ¿±°ÚÄÄ¿±°ÚÄÄÄÄÄÄÄÄÄÄ¿±°ÚÄÄÄÄ¿±²²²²±º
echo  º²²²²²°³%wdp%³±°³%dfp%³±°³%mfp%³±°³%year%³±²²²²±º
echo  º²²²²²°ÀÄÄÄÙ±°ÀÄÄÙ±°ÀÄÄÄÄÄÄÄÄÄÄÙ±°ÀÄÄÄÄÙ±²²²²±º
) else (
echo  º²²²²²²²²°ÚÄÄ¿±°ÚÄÄÄÄÄÄÄÄÄÄ¿±°ÚÄÄÄÄ¿±²²²²²²²²±º
echo  º²²²²²²²²°³%dfp%³±°³%mfp%³±°³%year%³±²²²²²²²²±º
echo  º²²²²²²²²°ÀÄÄÙ±°ÀÄÄÄÄÄÄÄÄÄÄÙ±°ÀÄÄÄÄÙ±²²²²²²²²±º
)
echo  º±±±±±±±²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²±±±±±±±±º
echo  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo     ÀÄÄÄÄÄÙ                           ÀÄÄÄÄÄÙ


set "th1=%day%%month%%year%%hour%%minute%"
:upd
REM Aacini - ping -n 20 localhost >nul
call :getdate
set "th2=%day%%month%%year%%hour%%minute%"

if "%th1%"=="%th2%" goto upd
goto :clock

:getdate
set "tf=~%random%"
type nul >"%temp%\%tf%.ddf"
makecab /d rptfilename="%temp%\%tf%.rpt" /d inffilename=nul /f "%temp%\%tf%.ddf" >nul
set /p "timestamp=" <"%temp%\%tf%.rpt"
for /f "tokens=3-9 delims=: " %%a in ("%timestamp%") 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"
)
del "%temp%\%tf%.ddf" "%temp%\%tf%.rpt" 2>nul
goto :eof


Antonio

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: [code] Batch Clock Widget

#6 Post by carlos » 26 Oct 2013 04:25

@Aacini: thanks for the idea. I write a more short version. If you look i use you idea of array, but is different.

Please update.

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: [code] Batch Clock Widget

#7 Post by Aacini » 26 Oct 2013 18:38

@carlos: Yes, in this case substring extractions are simpler than array elements management...

I just got a different model of the same brand! :mrgreen: BTW, what "MxPower" mean?

EDIT: I edited the code below, so now it includes several options that may be selected via parameters. For details, type: CLOCK /?
EDIT: Oct/30/2013 - The code below includes alarm and timer, and a preliminary version of calendar.
EDIT: 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.

Image Image Image Image

The example clocks above were started with the following commands:

  1. Clock.bat /S:0 Size=0: Minimum size, thin font; just one bottom line that is shared by the date and timer/alarm.
  2. Clock.bat /S:1 Size=1: Minimum size with bold font; there are separated lines for date and timer/alarm.
  3. Clock.bat /S:2 Size=2: The smallest size with full layout, but no day of week.
  4. Clock.bat /C Full layout with calendar.

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


Antonio
Last edited by Aacini on 05 Nov 2013 02:12, edited 8 times in total.

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: [code] Batch Clock Widget

#8 Post by carlos » 26 Oct 2013 20:50

Very good Aacini. I like your version more than mine. I post a link a image in the first post.
"MxPower" is the credit name of the author of the first skin. Originally I thinked that "MxPower" was a clock brand, but not, but looks like a brand.

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: [code] Batch Clock Widget

#9 Post by Dos_Probie » 28 Oct 2013 14:01

Good Job Carlos!! , Nice graphics with the 24h clock, I revised your Model1 by fixing the jule typo error to july and added upper case to each Month and also the Day of the week because of being a proper English noun (I thing its lower in Spanish) and also have it stand out better. Only other thing you might consider is doing a 12hr version as well and adding a shaded frame on left side to match the right side. DP 8)

Code: Select all

set "m= January   February   March     April      May       June   "
set "m=%m%   July     August  September  October   November  December "
set "w=MonTueWedThuFriSatSun"

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: [code] Batch Clock Widget

#10 Post by carlos » 28 Oct 2013 14:45

@Dos_Probie: thanks. I added your changes to the code. I am thinking add the 12 hours version and also a calendar of the month.

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: [code] Batch Clock Widget

#11 Post by Dos_Probie » 28 Oct 2013 18:26

carlos wrote:@Dos_Probie: thanks. I added your changes to the code. I am thinking add the 12 hours version and also a calendar of the month.


Sounds good Carlos, btw check your pm..DP 8)

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: [code] Batch Clock Widget

#12 Post by carlos » 28 Oct 2013 18:42

well, i will code all the ideas coming soon. If you want write it will be useful for save time.

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: [code] Batch Clock Widget

#13 Post by Aacini » 28 Oct 2013 18:44

A new model of the MxPower clock is here! :D This one have 12-hour format, two sizes (normal and small) and 4 levels of brightness, all of them selectable via parameters. You may get a small help via /? switch, for example:

Code: Select all

C:> clock /?
Clock.bat [/W] [/12] [/S] [/D] [/B:#] [/T:m] [/A:hh:mm]
   /W        Show week day
   /12       Set 12 hour format
   /S        Set small size (cancel /W)
   /D        Show blinking dots in hour    (*)
   /B:#      Set brightness from 0 to 3
   /T:m      Set timer in minutes          (*)
   /A:hh:mm  Set alarm time                (*) Under development

I edited the code in the previous post so it now includes this new version.

Antonio

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: [code] Batch Clock Widget

#14 Post by Dos_Probie » 28 Oct 2013 19:55

Aacini wrote:A new model of the MxPower clock is here! :D This one have 12-hour format, two sizes (normal and small) and 4 levels of brightness, all of them selectable via parameters. You may get a small help via /? switch, for example:

Code: Select all

C:> clock /?
Clock.bat [/W] [/12] [/S] [/D] [/B:#] [/T:m] [/A:hh:mm]
   /W        Show week day
   /12       Set 12 hour format
   /S        Set small size (cancel /W)
   /D        Show blinking dots in hour    (*)
   /B:#      Set brightness from 0 to 3
   /T:m      Set timer in minutes          (*)
   /A:hh:mm  Set alarm time                (*) Under development

I edited the code in the previous post so it now includes this new version.

Antonio

Good Job Aacini, Like how you have everything balanced and centered. How do you implement the 12 hr format?

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: [code] Batch Clock Widget

#15 Post by carlos » 28 Oct 2013 20:14

@Aacini: good code.

I'm sure that we can optimize replacing if else for:

Code: Select all

set /a "h1=hour/10,h2=hour-10*h1"
set /a "m1=minute/10,m2=minute-10*m1"


Or other arithmetic operation.

that is better than old:

Code: Select all

if %hour% lss 10 (set /a "h1=0,h2=%hour%"
) else set /a "h1=%hour:~0,1%,h2=%hour:~1,1%"
if %minute% lss 10 (set /a "m1=0,m2=%minute%"
) else set /a "m1=%minute:~0,1%,m2=%minute:~1,1%"

Post Reply