1

Not really a batch file user (more of a python guy here) wanting to get an output to just show the video title in a MS Edge YouTube tab (ultimately into a txt file, but I am going one step at a time and don't wanna waste too much of peoples time asking things on here. But I hit like 5 hours of debugging and searching how substrings work)

The batch I have made for testing is

@ECHO OFF
SET LIST=tasklist /fi "imagename eq msedge.exe" /fo list /v 
SET TITLE=%LIST%|findstr YouTube
SET OUTPUT=%TITLE:~14,-39%
ECHO %OUTPUT%

gives

~14,-39%


For a reference example

tasklist /fi "imagename eq msedge.exe" /fo list /v | findstr YouTube

in cmd the prompt gives me

Window Title: Skyline Drive & The Polaris Airship - Sunrise Over Sterling [Silk Music] - YouTube - Personal - Microsoft? Edge

But if someone knows how to grab the Windows 10 music toast notification area and plop it into a text file instead of having to use the WINDOWTITLE part of tasklist, that would be amazing. Even in like Node.js, Python, or really anything low intensity I can launch in Win 10.

3
  • You aren't actually doing anything . See for /?. Commented Mar 20, 2021 at 19:24
  • 2
    for /f "delims=" %%a in ('tasklist /fi "imagename eq msedge.exe" /fo list /v ^| findstr YouTube') do set "title=%%a" Commented Mar 20, 2021 at 22:57
  • Thank you, I just needed to add echo %title:~14,-39% >> /Desktop/title.txt and that works! How do I give you the answer point? Commented Mar 21, 2021 at 1:49

1 Answer 1

1

In batch set variable=command doesn't work. It assigns the literal string to the variable, not the output of the command. To do that, you need a for /f loop:

for /f "delims=" %%a in ('tasklist /fi "imagename eq msedge.exe" /fo list /v ^| findstr YouTube') do set "title=%%a"
echo %title:~14,-39% >> /Desktop/title.txt

Usually, you can define which part of the output you return with proper tokens and delims (see for /?), but in this case, it's better to get the whole line and post-process it, as the tokens differ in different languages (English: Window title (two tokens), German: Fenstertitel (one token))

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.