Introduction: Different Colors in Batch File and Others

About: some random guy who likes doing random things

introduction

This guide features multiple useful Batch utilities such as a multiline color command, in which past me will explain: The color command in batch files changes the color of the terminal. This is very limited however as it does it for the entire screen, instead of one line. I have made a function that allows you to change the color of each individual line. Credit to Prof. Pickle for the idea.


Also if you don't want to do utility one at least read how to make it so you know how to use them as I won't be explaining it in any other utility. You are also expected to repeat the same for any other utilities in this guide. Or you can just use an installer I made in the bottom.


I am also planning to add more utilities! Suggestions appreciated.


installer instructions

Download Python 3.14

Download the installer here

Then extract it into a folder

Open the terminal in that folder with admin privileges

Run 'pip install -r requirements.txt'

Run 'python main.py'

If it is your first time installing it will say that it detected an invalid folder. As long as you don't happen to have any important things in that folder you can safely confirm.

It might also say something with "PermissionError" in it. If this happens it means you did not run the terminal with admin privileges and you need to run it again.

Supplies

A Windows Computer (preferably 7+)

A text editor (any will work)

Basic knowledge of computers (how to navigate folders, etc.)

Step 1: Utility 1

Different Colors In Batch File

Copy this code and paste it to EXACTLY this file name: fecho.bat

@echo off

REM named "fecho" bcs it stands for formatted echo

if "%~1"=="/?" goto :showhelp
if "%~1"=="" goto :showhelp
if "%~2"=="" goto :showhelp

set "text=%~1"
set "color=%~2"

powershell -Command "Write-Host \"%text%\" -ForegroundColor %color%"
goto :eof

:showhelp
echo Prints text with a custom color.
echo:
echo FECHO [text] [color]
echo:
echo text The text to print
echo color Specifies color of text
echo:
echo Use the chart below for possible COLOR attributes (case-sensitive):
echo:
echo Black
echo DarkBlue
echo DarkGreen
echo DarkCyan
echo DarkRed
echo DarkMagenta
echo DarkYellow
echo Gray
echo DarkGray
echo Blue
echo Green
echo Cyan
echo Red
echo Magenta
echo Yellow
echo White


Create a folder wherever you would like.

Go to "Edit the system environment variables" by using the Start menu search bar.

Click "Environment Variables," select "Path" under "System variables," then "Edit," then "Browse," and select the folder you just made.

Place the fecho.bat file we made earlier in the folder.

Restart any terminals you want to use it in and you're ready to go.

I would also recommend using the same folder for my other custom Batch commands, but do whatever you want.


You might also know that Prof. Pickle said to place the custom commands in System32, and I will clear that up. Basically, whenever you enter a command in CMD, the system looks for an executable file with the name corresponding to the command you just entered that is in a folder on PATH. System32 is included by default on PATH so that's why it works. However I recommend this method as putting random commands in System32 is messy and this method allows you to keep everything organized and in a custom folder. This is also the standard way to install most developer CLI tools so it is widely recognized.


Open the cmd and type in:

fecho /?

This will give you the info on how to use it. For example:

fecho "Hello, World!" Yellow

returns this:


This should work also in Batch scripts but if it doesn't use this instead:

call fecho *parameters*

Step 2: Utility 2

Weather Utility

Copy this code and paste it EXACTLY into this file: getweather.bat:

@echo off

REM ORIGINAL_LINK="none"

if "%~1"=="/?" ( goto :showhelp )

set "url=https://wttr.in/?format=%C%0D%0A%t,%20Feels%20Like%20%f%0D%0AHumidity:%20%h%0D%0AWind:%20%w%0D%0APrecipitation:%20%p%20mm%20per%203hrs%0D%0APressure:%20%P%0D%0AUV%20Index:%20%u"
set "curl_installed=false"

where curl >nul 2>&1
if ERRORLEVEL EQU 0 (
set "curl_installed=true"
)

REM Do the check for Powershell now and compare ERRORLEVEL later if needed.
where /Q "powershell"

if "%curl_installed%"=="true" (
curl %url%
) else if ERRORLEVEL EQU 0 (
powershell -Command "Invoke-RestMethod -Uri '%url%'"
) else (
echo No suitable method to fetch weather data found. Please install curl or add Powershell to PATH.
exit /b 1
)

goto :eof

:showhelp
echo Returns the weather.
echo:
echo GETWEATHER
echo:
echo This command REQUIRES curl or Powershell available on PATH.
echo This command also uses the wttr.in API. You can find the
echo full URL in %~dp0%.

goto :eof

Also note that this requires an internet connection.

Step 3: Utility 3

Fun Fact Utility

Copy and paste this code into a file with EXACTLY this name: funfact.bat:

@echo off

if "%~1"=="/?" ( goto :showhelp )

set "url=https://uselessfacts.jsph.pl/random.json"

where /Q "powershell"

if ERRORLEVEL EQU 0 (
powershell -NoProfile -Command ^
"$json = Invoke-RestMethod -Uri '%url%'; ^
$obj = $json | ConvertFrom-Json; ^
$fact = $obj.text; ^
Write-Host $fact;"
) else (
echo No suitable method to fetch random facts found. Please add Powershell to PATH.
exit /b 1
)

goto :eof

:showhelp
echo Returns a random fun fact.
echo:
echo FUNFACT
echo:
echo This command REQUIRES Powershell available on path.
echo This command uses the Useless Facts API at
echo https://uselessfacts.jsph.pl/. The actual API endpoint
echo is at https://uselessfacts.jsph.pl/random.json.

goto :eof

This also requires an internet connection.

Step 4: