Set Variable to [window name matching regex]

I need to find which WindowName (%WindowName%1%, %WindowName%2%, etc) in a specific application matches a regex, and set a Variable to whatever that WindowName happens to be.

Seems like it should be easy, but I'm stumped.

Due to restraints, I cannot Bring Window(s) With Name Matching “regex” to Front and then set the Variable to %WindowName%1%.

I also tried to parse Christopher Stone's super-handy List Windows Keyboard Maestro Can See v1.1 for clues but I lack the knowledge.

Thanks in advance!

Can you post your macro as well as an example of the kind of thing you're trying to match in the window title? There might be an alternative to using regex.

Methods of window-name reading vary between applications.

  • Which application are we talking about ?

  • What kind of string pattern does your regex aim to match, and what does the regex look like ?

  • What kind of names do the windows have ?


Show works, but tell usually fails.

1 Like
  • Which application are we talking about ?

Ableton Live

  • What kind of string pattern does your regex aim to match, and what does the regex look like ?

Matches brackets [[^]]*]
(this part already works)

  • What kind of names do the windows have ?

The other possible windows generally don't have brackets, hence my regex :slight_smile: here's an example:
image

In this example, I want to track %WindowName%3%, Like That 0.2 [Like That] which is the project filename, so I can know, among other things, when a new file is opened. But sometimes it's window3 like above, sometimes 1 or 2 — it switches from moment to moment. If I can Set a Variable to window name matching [[^]]*], then it would allow me to search for that WindowName every time the focused window title changes (only Ableton windows of course), and know if a new file is opened.

If there's a way to flip through the windows, find which window matches [[^]]*], and put that window name in a variable, I think that would work.

@nrightnour Why not just track window titles containing a square bracket? I don't see the need for regex.

@noisneil If it solves a problem then I'd be willing to simplify it to just one bracket, which would probably be fine.

Also I found a post that has a similar function to what I think I'm looking for (listing windows and finding a specific window via title) but for a different purpose:

@nrightnour You can get the current file name from File > Open Recent Set.

Try this:

Track Window Titles.kmmacros (24 KB)

Macro screenshot

1 Like

Thank you @noisneil! I've been fiddling with it for a bit and think I managed to integrate it into my main macro.

Sending you a DM as well.

1 Like