3

Let's say I'm running a browser window and the title of the window is something like "Title Here - Mozilla Firefox." I want to constantly update a .txt file that contains the title of this window, meaning the .txt file should change as the title bar changes (doesn't have to be instant, maybe every 1 second).

I already know this is possible on Linux with wmctrl and a little scripting, but I would like to do this on Windows 10.

How can I go about making this? What applications or SDKs would I need?

EDIT: If anyone is curious to see the Powershell script I ended up with, here you go. Save it as a .ps1 to run (and be sure to enable Powershell scripts.)

2 Answers 2

4

This should get you started using PowerShell. The code was adapted from a MSDN blog and from a StackOverflow answer by Keith Hill. See his answer for parameter description.

$period = [timespan]::FromSeconds(5) $lastRunTime = [DateTime]::MinValue while (1) { while ((Get-Date) - $lastRunTime -lt $period) { Start-Sleep -Milliseconds 500 } $lastRunTime = Get-Date Get-Process |where {$_.MainWindowTitle} |format-table MainWindowTitle –AutoSize > c:\users\username\title.txt }

0

I suspect this is not the most elegant suggestion, but one that might work, especially if you are comfortable with creating scripts. Macro Express Pro is a program that works with Windows and has substantial features. The looping and logic controls within Macro Express are quite powerful. One of the features I discovered as part of this research is the ability to load a string variable with the current window's title bar. https://www.macros.com/help/Index.htm I used "title bar" as the search term and clicked on the Set String Variable entry. Scrolling down in the results shows:

Set Value To Top Most Window Title

Examines the window that is currently on top of all others, takes the name that is in the caption bar (i.e. the Window Title) and places it into a variable.

I lack the scripting skill to suggest how to process the string variable henceforth, as any actions would then change the window focus, but you may discover more flexibility than I in the overall program.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .