There are a few ways to set the title of a windows terminal tab, but no way to read the title #23446

Closed
opened 2026-01-31 08:42:25 +00:00 by claunia · 12 comments
Owner

Originally created by @markyoung2u on GitHub (Jul 17, 2025).

Description of the new feature

I setup a cmd prompt to open 5 different tabs. One for misc window stuff and the other 4 for compiling 2 UEFI apps in X64 and ARM64 modes. I'd like to "read" the title I set up with "wt -w 0 --title %tabtitle% cmd /k cmdSetup.bat xxxx" where tabtitle is set to different strings in the initial tab but each of the other 4 tabs do not know the value of %tabtitle%. It seems pretty basic if we can set the title we should be able to read it, too

Proposed technical implementation details

No response

Originally created by @markyoung2u on GitHub (Jul 17, 2025). ### Description of the new feature I setup a cmd prompt to open 5 different tabs. One for misc window stuff and the other 4 for compiling 2 UEFI apps in X64 and ARM64 modes. I'd like to "read" the title I set up with "wt -w 0 --title %tabtitle% cmd /k cmdSetup.bat xxxx" where tabtitle is set to different strings in the initial tab but each of the other 4 tabs do not know the value of %tabtitle%. It seems pretty basic if we can set the title we should be able to read it, too ### Proposed technical implementation details _No response_
claunia added the Issue-FeatureNeeds-TriageNeeds-Tag-Fix labels 2026-01-31 08:42:26 +00:00
Author
Owner

@DHowett commented on GitHub (Jul 17, 2025):

What would you do with the information you read?

@DHowett commented on GitHub (Jul 17, 2025): What would you do with the information you read?
Author
Owner

@markyoung2u commented on GitHub (Jul 17, 2025):

I want to set the prompt color initially, of the 2 tabs for arm64. Right now its a manual process with "promptColor arm"
@echo off
if .%1 == . (echo Ver 1.0 Usage: %0 WBDD{or1} ^|ePSA{or2}^|arm{or3}&echo WBDD fg/bg is white/black, epsa green/red, arm is aqua/red&goto :eof)
:: ePSA E[91m resets color to 91=LightRED or same as color 0C. see man prompt
set arg=%1
if /i .%1 == .wbdd set arg=1
if /i .%1 == .epsa set arg=2
if /i .%1 == .arm set arg=3
if /i .%arg% == .1 (set PROMPT=$E[92m$P$G$E[0m$S&goto :eof)
if /i .%arg% == .2 (set PROMPT=$E[92m$P$G$E[91m$S&goto :eof)
if /i .%arg% == .3 (set PROMPT=$E[92m$P$G$E[96m$S&goto :eof)
echo Invalid arg %1
goto :eof

@markyoung2u commented on GitHub (Jul 17, 2025): I want to set the prompt color initially, of the 2 tabs for arm64. Right now its a manual process with "promptColor arm" @echo off if .%1 == . (echo Ver 1.0 Usage: %0 WBDD{or1} ^|ePSA{or2}^|arm{or3}&echo WBDD fg/bg is white/black, epsa green/red, arm is aqua/red&goto :eof) :: ePSA E[91m resets color to 91=LightRED or same as color 0C. see man prompt set arg=%1 if /i .%1 == .wbdd set arg=1 if /i .%1 == .epsa set arg=2 if /i .%1 == .arm set arg=3 if /i .%arg% == .1 (set PROMPT=$E[92m$P$G$E[0m$S&goto :eof) if /i .%arg% == .2 (set PROMPT=$E[92m$P$G$E[91m$S&goto :eof) if /i .%arg% == .3 (set PROMPT=$E[92m$P$G$E[96m$S&goto :eof) echo Invalid arg %1 goto :eof
Author
Owner

@markyoung2u commented on GitHub (Jul 19, 2025):

To be clear, any arbitrary script can be specified in a the initial cmd.exe pinned to the taskbar:
%windir%\system32\cmd.exe /k cmdSetup epsa4
but NOTHING in cmdSetup.bat is passed on to the 3 epsa tab's EXCEPT the title itself, using "wt -w 0 --title %tabtitle% cmd /k cmdSetup.bat epsa4", so If I was able to "read" the title I could do more with the 4 tabs

@markyoung2u commented on GitHub (Jul 19, 2025): To be clear, any arbitrary script can be specified in a the initial cmd.exe pinned to the taskbar: %windir%\system32\cmd.exe /k cmdSetup epsa4 but NOTHING in cmdSetup.bat is passed on to the 3 epsa tab's EXCEPT the title itself, using "wt -w 0 --title %tabtitle% cmd /k cmdSetup.bat epsa4", so If I was able to "read" the title I could do more with the 4 tabs
Author
Owner

@markyoung2u commented on GitHub (Jul 22, 2025):

I found GetConsoleOriginalTitle can get the original title "ePSA_arm64" even though the displayed title has extra text appended run running scripts in the tab. Works perfectly. No need for this request

Image
@markyoung2u commented on GitHub (Jul 22, 2025): I found GetConsoleOriginalTitle can get the original title "ePSA_arm64" even though the displayed title has extra text appended run running scripts in the tab. Works perfectly. No need for this request <img width="391" height="197" alt="Image" src="https://github.com/user-attachments/assets/9e2cb95b-062f-48c8-aaab-3febe9425b1f" />
Author
Owner

@DHowett commented on GitHub (Jul 22, 2025):

Oh, that's great news.

The reason I was asking is that... well, since you control every process that runs inside Terminal, you can just make the decision when your script is running (like... set an environment variable or something) rather than making the decision after the fact by scrying into your host application.

@DHowett commented on GitHub (Jul 22, 2025): Oh, that's great news. The reason I was asking is that... well, since you control every process that runs inside Terminal, you can just make the decision _when your script is running_ (like... set an environment variable or something) rather than making the decision after the fact by scrying into your host application.
Author
Owner

@markyoung2u commented on GitHub (Jul 22, 2025):

No, I can't make any decision when the 5 tabs are being created as everything is happening in the 1st cmd window tab. The other 4 don't "see" anything different, Actually, this is still an issue. Yes, GetConsoleOriginalTitle works from a cmd tab, but No, it does not work when you run the shortcut that creates all 5 tabs at once because everything takes place inside the 1st tab, not the others. The "wt -w 0 --title %tabtitle% cmd /k cmdSetup.bat epsa4" called from the first tab and creates the other 4 is NOT able to make the other 4 do anything different, except the tab title. Fundamentally, the 4 tab only gets vars and args in the wt cmdline which are all the same. There is no way for the extra 4 tabs to get different information from the 1st.

@markyoung2u commented on GitHub (Jul 22, 2025): No, I can't make any decision when the 5 tabs are being created as everything is happening in the 1st cmd window tab. The other 4 don't "see" anything different, Actually, this is still an issue. Yes, GetConsoleOriginalTitle works from a cmd tab, but No, it does not work when you run the shortcut that creates all 5 tabs at once because everything takes place inside the 1st tab, not the others. The "wt -w 0 --title %tabtitle% cmd /k cmdSetup.bat epsa4" called from the first tab and creates the other 4 is NOT able to make the other 4 do anything different, except the tab title. Fundamentally, the 4 tab only gets vars and args in the wt cmdline which are all the same. There is no way for the extra 4 tabs to get different information from the 1st.
Author
Owner

@DHowett commented on GitHub (Jul 22, 2025):

You are spawning a process (or four processes) inside Terminal using wt ... commandline. You can surely put something in either commandline or the environment (wt ... commandline spawns a process which inherits environment variables from its parent...) that will be more durable than the title of the inferred console window.

@DHowett commented on GitHub (Jul 22, 2025): _You are spawning a process (or four processes) inside Terminal using `wt ... commandline`._ You can _surely_ put something in either `commandline` or the environment (`wt ... commandline` spawns a process which inherits environment variables from its parent...) that will be more durable than the title of the inferred console window.
Author
Owner

@markyoung2u commented on GitHub (Jul 22, 2025):

I just now got it to work. Not in the wt commandline, not in the cmdSetup.bat and not in userwt.bat called by cmdSetup.bat - these do not work. I put the title-reading customization in a yet another batch called by all the tabs. and that works. It's not especially clever nor obvious. There are no environment variables that will work as they all inherit from the 1st tab.

@markyoung2u commented on GitHub (Jul 22, 2025): I just now got it to work. Not in the wt commandline, not in the cmdSetup.bat and not in userwt.bat called by cmdSetup.bat - these do not work. I put the title-reading customization in a yet another batch called by all the tabs. and that works. It's not especially clever nor obvious. There are no environment variables that will work as they all inherit from the 1st tab.
Author
Owner

@DHowett commented on GitHub (Jul 23, 2025):

I think I have a vastly incorrect understanding of the system you've created.

I expected something like this:

REM cmdsetup.bat
userwt something
userwt somethingelse
userwt anotherthing
REM userwt.bat

REM do something with %1, %2, %3, calculate something, etc

wt nt my_special_command_1 %CALCULATED_VALUE_FROM_ABOVE%

or something like this:

REM cmdsetup.bat
wt nt userwt something
wt nt userwt somethingelse
wt nt userwt anotherthing
REM userwt.bat
REM do something with %1, %2, %3, calculate something, etc

my_special_command_1 %CALCULATED_VALUE_FROM_ABOVE%

and then in both cases, you'd launch wt nt --title foo cmdstartup.bat or something.


In both of those instances, you have control inside cmdsetup and inside userwt about the things that run after. You can pass arguments, set environment variables, etc.

When I read what you said most recently, however, it makes it sound like you don't have control over cmdSetup or userwt, and you are working at the tail end of a complicated system that you don't have much control over. That would make sense I think.

@DHowett commented on GitHub (Jul 23, 2025): I think I have a vastly incorrect understanding of the system you've created. I expected something like this: ``` REM cmdsetup.bat userwt something userwt somethingelse userwt anotherthing ``` ``` REM userwt.bat REM do something with %1, %2, %3, calculate something, etc wt nt my_special_command_1 %CALCULATED_VALUE_FROM_ABOVE% ``` _or something like this_: ``` REM cmdsetup.bat wt nt userwt something wt nt userwt somethingelse wt nt userwt anotherthing ``` ``` REM userwt.bat REM do something with %1, %2, %3, calculate something, etc my_special_command_1 %CALCULATED_VALUE_FROM_ABOVE% ``` and then in both cases, you'd launch `wt nt --title foo cmdstartup.bat` or something. --- In both of those instances, you have control inside cmdsetup _and inside userwt_ about the things that run after. You can pass arguments, set environment variables, etc. When I read what you said most recently, however, it makes it sound like you don't have control over `cmdSetup` _or_ `userwt`, and you are working at the tail end of a complicated system that you don't have much control over. That would make sense I think.
Author
Owner

@markyoung2u commented on GitHub (Jul 23, 2025):

It's more like this. The taskbar icon to create all 5 tabs is "%windir%\system32\cmd.exe /k cmdSetup epsa4"
cmdSetup and userwt.bat I have full control over. cmdSetup does several things, the main ones are:
call vsToRun.bat {to decide which VS version to run and currently VS2022}
Decide what to do based on epsa4 arg, but if it is epsa4 does below. %tabtitle% is NOT seen by userwt,.bat nor any args, either
set tabtitle=ePSA
call userwt %tabtitle%

set tabtitle=ePSA_arm64
call userwt %tabtitle%

set tabtitle=Nautilus
call userwt %tabtitle%

set tabtitle=Nautilus_arm64
call userwt %tabtitle%

The solution was to basically call a new script pc.bat from inside vsToRun.bat and pc.bat is below. I'm not actually using GetConsoleOriginalTitle anymore because I put it in an exe that has too much already and is too slow. Today I tried to get the same functionality with powershell and it works, but is pretty messy due A. It gets the current title which is the original title plus more additions as scripts are run, and B. Trying to get just the original title and not any appended strings, and C. making it work for either case. At least it works. "PromptColor.bat arm" changes the prompt to aqua text color from other colors.
@echo off
:: Extra customization to make arm64 cmd window tabs a bit different
:: Any SPACE in title?
for /F "usebackq delims=" %%v in (powershell -command "$Host.UI.RawUI.WindowTitle.IndexOf(' ')") do set origLen=%%v
:: No, just return the title when %origLen% is -1
if "%origLen%" == "-1" for /F "usebackq delims=" %%v in (powershell -command "$Host.UI.RawUI.WindowTitle") do set origTitle=%%v
:: Yes, return the substring of the title
if "%origLen%" GTR "-1" for /F "usebackq delims=" %%v in (powershell -command "$Host.UI.RawUI.WindowTitle.Substring(0, %origLen%)") do set origTitle=%%v
::echo TAB origTitle: %origTitle%
if "%origTitle%" == "ePSA_arm64" call promptColor arm
if "%origTitle%" == "Nautilus_arm64" call promptColor arm

@markyoung2u commented on GitHub (Jul 23, 2025): It's more like this. The taskbar icon to create all 5 tabs is "%windir%\system32\cmd.exe /k cmdSetup epsa4" cmdSetup and userwt.bat I have full control over. cmdSetup does several things, the main ones are: call vsToRun.bat {to decide which VS version to run and currently VS2022} Decide what to do based on epsa4 arg, but if it is epsa4 does below. %tabtitle% is NOT seen by userwt,.bat nor any args, either set tabtitle=ePSA call userwt %tabtitle% set tabtitle=ePSA_arm64 call userwt %tabtitle% set tabtitle=Nautilus call userwt %tabtitle% set tabtitle=Nautilus_arm64 call userwt %tabtitle% The solution was to basically call a new script pc.bat from inside vsToRun.bat and pc.bat is below. I'm not actually using GetConsoleOriginalTitle anymore because I put it in an exe that has too much already and is too slow. Today I tried to get the same functionality with powershell and it works, but is pretty messy due A. It gets the current title which is the original title plus more additions as scripts are run, and B. Trying to get just the original title and not any appended strings, and C. making it work for either case. At least it works. "PromptColor.bat arm" changes the prompt to aqua text color from other colors. @echo off :: Extra customization to make arm64 cmd window tabs a bit different :: Any SPACE in title? for /F "usebackq delims=" %%v in (`powershell -command "$Host.UI.RawUI.WindowTitle.IndexOf(' ')"`) do set origLen=%%v :: No, just return the title when %origLen% is -1 if "%origLen%" == "-1" for /F "usebackq delims=" %%v in (`powershell -command "$Host.UI.RawUI.WindowTitle"`) do set origTitle=%%v :: Yes, return the substring of the title if "%origLen%" GTR "-1" for /F "usebackq delims=" %%v in (`powershell -command "$Host.UI.RawUI.WindowTitle.Substring(0, %origLen%)"`) do set origTitle=%%v ::echo TAB origTitle: %origTitle% if "%origTitle%" == "ePSA_arm64" call promptColor arm if "%origTitle%" == "Nautilus_arm64" call promptColor arm
Author
Owner

@DHowett commented on GitHub (Jul 23, 2025):

%tabtitle% is NOT seen by userwt,.bat nor any args, either

Isn't it literally being included in the arguments for userwt?

call userwt %tabtitle%

Inside userwt, don't you receive that as %1?

@DHowett commented on GitHub (Jul 23, 2025): > %tabtitle% is NOT seen by userwt,.bat nor any args, either Isn't it literally being included in the arguments for userwt? > call userwt %tabtitle% Inside userwt, don't you receive that as `%1`?
Author
Owner

@markyoung2u commented on GitHub (Jul 23, 2025):

Yes, I have %tabtitle% set and passed to userwt.bat but neither are "seen" except in the 1st tab. That is what I've been struggling with...

@markyoung2u commented on GitHub (Jul 23, 2025): Yes, I have %tabtitle% set and passed to userwt.bat but neither are "seen" except in the 1st tab. That is what I've been struggling with...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#23446