Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

batch-file

cmd

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 
like image 209
diti Avatar asked Sep 24 '12 20:09

diti


People also ask

Can CMD display colors?

Color is an inbuilt command found inside the Windows Command Processor (cmd.exe), that is used for changing the colors for the console's foreground and background. By default, the console has white foreground color and black background color (07 color code).

What is %% A in batch script?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.

How do you change the color of text in CMD?

To set the default Command Prompt window color, select the upper-left corner of the Command Prompt window, select Defaults, select the Colors tab, and then select the colors that you want to use for the Screen Text and Screen Background.


2 Answers

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     ) ) 
like image 63
Mark Avatar answered Oct 09 '22 12:10

Mark


Try this script. This can write any text on any position of screen and don't use temporary files or ".com, .exe" executables. Just make shure you have the "debug.exe" executable in windows\system or windows\system32 folders.

http://pastebin.com/bzYhfLGc

@echo off setlocal enabledelayedexpansion set /a _er=0 set /a _n=0 set _ln=%~4 goto init   :howuse ---------------------------------------------------------------      echo ------------------     echo ECOL.BAT - ver 1.0     echo ------------------     echo Print colored text in batch script     echo Written by BrendanLS - http://640kbworld.forum.st     echo.     echo Syntax:     echo ECOL.BAT [COLOR] [X] [Y] "Insert your text"     echo COLOR value must be a hexadecimal number     echo.     echo Example:     echo ECOL.BAT F0 20 30 "The 640KB World Forum"     echo.     echo Enjoy ;^)     goto quit  :error ----------------------------------------------------------------      set /a "_er=_er | (%~1)"     goto quit  :geth -----------------------------------------------------------------          set return=         set bts=%~1  :hshift ---------------------------------------------------------------          set /a "nn = bts & 0xff"         set return=!h%nn%!%return%         set /a "bts = bts >> 0x8"         if %bts% gtr 0 goto hshift         goto quit  :init -----------------------------------------------------------------      if "%~4"=="" call :error 0xff      (         set /a _cl=0x%1         call :error !errorlevel!         set _cl=%1         call :error "0x!_cl! ^>^> 8"         set /a _px=%2         call :error !errorlevel!         set /a _py=%3         call :error !errorlevel!     ) 2>nul 1>&2      if !_er! neq 0 (         echo.         echo ERROR: value exception "!_er!" occurred.         echo.         goto howuse     )      set nsys=0123456789abcdef     set /a _val=-1          for /l %%a in (0,1,15) do (                 for /l %%b in (0,1,15) do (                         set /a "_val += 1"                         set byte=!nsys:~%%a,1!!nsys:~%%b,1!                         set h!_val!=!byte!                 )         )      set /a cnb=0     set /a cnl=0  :parse ----------------------------------------------------------------      set _ch=!_ln:~%_n%,1!     if "%_ch%"=="" goto perform      set /a "cnb += 1"     if %cnb% gtr 7 (         set /a cnb=0         set /a "cnl += 1"     )      set bln%cnl%=!bln%cnl%! "!_ch!" %_cl%     set /a "_n += 1"     goto parse  :perform --------------------------------------------------------------      set /a "in = ((_py * 160) + (_px * 2)) & 0xffff"     call :geth %in%     set ntr=!return!     set /a jmp=0xe       @for /l %%x in (0,1,%cnl%) do (         set bl8086%%x=eb800:!ntr! !bln%%x!         set /a "in=!jmp! + 0x!ntr!"         call :geth !in!         set ntr=!return!         set /a jmp=0x10     )      (     echo.%bl80860%&echo.%bl80861%&echo.%bl80862%&echo.%bl80863%&echo.%bl80864%     echo.q     )|debug >nul 2>&1  :quit 
like image 40
LucasLynx Avatar answered Oct 09 '22 11:10

LucasLynx