I keep finding myself wanting to iterate over the windows of a specific or front application. I end up going into AppleScript for this. Is there / should there be a For Each variation for this? (The case at hand is closing all Safari Web Inspector windows, because every time I run a JXA script I get a new window, so they proliferate.)
You could start with something like this:
Works also without the “While” condition. Just:
Ah. Missed that variation on the While conditions and the Window action. Both of those will work for my immediate need and most others, so thanks. For anything where I need to do something that is not included in the while conditions and window actions its no problem to resort to AppleScript, but it looks like most of what I need is included in KM (as always :-)).
Hey Mitchell,
I prefer to use AppleScript for that sort of thing when possible, but it's easy enough iterate through windows by index with Keyboard Maestro:
If you look at my List Windows Keyboard Maestro Can See v1.1 macro you'll find some more techniques.
-Chris