Search code examples
cmdbatch-file

How to change text color of cmd with windows batch script every 1 second


The color command has to do with changing color of windows command promt background/text

color 0A - where 0 is the background color and A is the text color

I want to change these color of text every 1 second in windows batch script using an array with 1,2,3,4,5,6,7,8,9,A,B,C,D,E,F witch are the color codes.

0 = Black       8 = Gray
1 = Blue        9 = Light Blue
2 = Green       A = Light Green
3 = Aqua        B = Light Aqua
4 = Red         C = Light Red
5 = Purple      D = Light Purple
6 = Yellow      E = Light Yellow
7 = White       F = Bright White

the command should be go every second like this

color 01
color 02
color 03
....
color 0E
color 0F

and for these i found some little script but im not sure how to make it work to change the color for every 1 second!

for /L %%i in (1,1,%n%) do echo !array[%%i]!

or this

@echo off CLS
for /l %%a in (15,-1,1) do (
color 0A
cls
)
pause

or this

SET COUNTDOWN=15
:COUNTDOWNLOOP
IF %COUNTDOWN%==0 GOTO END
color 0A && %R1%
CLS
SET /A COUNTDOWN -=1
GOTO COUNTDOWNLOOP
:END

Solution

  • This should fit the bill. Sounds like a super-annoying thing to have going on, but there you have it:

    @echo off
    set NUM=0 1 2 3 4 5 6 7 8 9 A B C D E F
    for %%x in (%NUM%) do ( 
        for %%y in (%NUM%) do (
            color %%x%%y
            timeout 1 >nul
        )
    )