Set title as time

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Set title as time

#1 Post by batchcc » 04 Oct 2015 11:53

I have a question I was wondering how you can change the title every time the minute changes and not display the seconds just hour:minute
This is wat I have so far.

Code: Select all

@echo off
Cls
set h=%TIME:~0,2%
set m=%TIME:~3,2%
set titletime=%h%:%m%
Title %titletime%
Pause

But I want the code to continue and be able to do something else rather than just go back and reset the title every minute can I make the title change automatically
Thanks

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Set title as time

#2 Post by aGerman » 04 Oct 2015 14:32

Batch isn't made for such things. To answer your question: You may achieve it if you're running two Batch processes in the same window at the same time (START /B). It's ugly and I don't recommend it.

Code: Select all

@echo off &setlocal
if "%~1"=="proctime" (call :proctime) else start /b cmd /c "%~fs0" proctime

:: Do something meaningful here
pause

exit /b

:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:proctime
setlocal EnableDelayedExpansion
for /l %%i in () do (
  set "ttl=!time:~,5!"
  title !ttl!
  for /f %%j in ('tasklist /fi "imagename eq cmd.exe" /fi "windowtitle eq !ttl!" /nh ^| find /c /v ""') do if %%j lss 2 exit
  >nul timeout /t 1 /nobreak
)

Regards
aGerman

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

Re: Set title as time

#3 Post by foxidrive » 04 Oct 2015 18:29

batchcc wrote:But I want the code to continue and be able to do something else


Such as what? The batch code you are using can incorporate different styles up updating the title, but without you telling us what you are doing you will never get the most appropriate solution.

Post Reply