I found some code online that does this, but I have very limited experience with command line stuff and this particular code example is utterly impenetrable to me.
Code: Select all
@(Set/P "=The color is currently set to "<NUL&For /F %%# In ('^""%__AppDir__%WindowsPowerShell\v1.0\powershell.exe" -NoP "$Console=(Get-Host).UI.RawUI;Switch($Console.BackgroundColor,$Console.ForegroundColor){'Black'{'0'}'DarkBlue'{'1'}'DarkGreen'{'2'}'DarkCyan'{'3'}'DarkRed'{'4'}'DarkMagenta'{'5'}'DarkYellow'{'6'}'Gray'{'7'}'DarkGray'{'8'}'Blue'{'9'}'Green'{'A'}'Cyan'{'B'}'Red'{'C'}'Magenta'{'D'}'Yellow'{'E'}'White'{'F'}}" 2^>NUL^"')Do @Set/P=%%#<NUL)&Echo(&Pause
I've seen other code examples where the variable was clearly identifiable. I could then compare that variable against some strings of my choosing and then take the necessary action based on various matches. But in this example I don't even know where the variable is!
How can I put the output of the code above (only the 2 character hex value, not the preamble text) into a variable, and then take one action if the variable matches 0B and another action if the variable matches 0F?
I intend to run this from an alias (doskey) so that I can just type the command and have the correct action taken based on the text color of the current console.
I appreciate any and all help. Thanks.