I would like to create a batch file countdown timer (needs to be batch script due to restrictions in place). I've used two scripts so far that 'kind of' do the job, but have their own downsides.
The criteria is as follows: 1. Needs to show system time in xx:xx:xx format. 2. Needs to countdown in minutes + seconds in xx:xx format. 3. Needs to be able to work in 12 hour blocks (e.g. 7pm to 7am)
The countdown script I've been using (not my own creation, I've just modified certain sections) is as follows:
@echo off
setlocal
REM This script starts countdown from time you open batch file.
REM Open at 19:00:23 and it will finish at 07:00:23 (it's range is 60 seconds)
REM This can be checked against http://www.rechnr.com/online-calculator/how-many-hours-left-until-tomorrow-calculator.html
:settime1
rem Get end time
REM for /F "tokens=1,2 delims=:" %%a in ("ResponseTime.txt") do set /A endH=10%%a%%100, endM=1%%b%%100
REM Just for testing:
set endH=07
set endM=00
title Timer
mode con cols=20 lines=2
:synchronize
for /F "tokens=1,2 delims=:" %%a in ("%time%") do set /A "minutes=(endH*60+endM)-(%%a*60+1%%b-100)-1, seconds=159"
:wait
timeout /T 1 /NOBREAK > NUL
echo Shift End: %minutes%:%seconds:~-2%
set /A seconds-=1
if %seconds% geq 100 goto wait
set /A minutes-=1, seconds=159, minMOD5=minutes %% 5
if %minutes% lss 0 goto :buzz
if %minMOD5% equ 0 goto synchronize
goto wait
:buzz
mode con cols=100 lines=30
echo End of Shift
SET /P ANSWER=Would you like to shut down the machine (Y/N)?
echo You chose: %ANSWER%
if /i {%ANSWER%}=={y} (goto :yes)
if /i {%ANSWER%}=={yes} (goto :yes)
goto :no
:yes
echo Shutting down
shutdown /s /t 5 /c "Shutting down in 5 seconds"
pause > nul
exit /b 0
:no
echo You pressed no!
pause > nul
exit /b 1
The downside to this code is that it doesn't synchronise to the system clock, thus it becomes out of sync, also it doesn't work before midnight for the night shift.
Any help refining this would be fantastic, unsure really how to use the system clock as the synchronise variable for countdown.
Thanks!
Some time ago I modified a someone else's clock written in pure Batch and give it an alarm and timer, and several "skins". This is the help screen of such program:
This is the /Size:1 skin with counting timer, and also when the timer ends:
You may download such a program from this site.