Need macro that will swap focus between 2 active open windows (split)

Say I have 2 windows open split 50/50.

If I have left window in focus, I want to switch to the right window. If I have right, this same macro will switch focus to left window.

How can I do this without resorting to click mouse in left/right corner. Perhaps there is safe, fast way to do this?

In most Mac apps, Command-Tilde will swap between the open windows—does that not work for your use case, or in the app you're using?

And if it does work but you need it in a macro, just send the Command-Tilde keystroke via the macro.

-rob.

Does not work as I often have more than 6 windows open of same app (my editor).

If you have six windows open, then you're going to have to rely on clicking at a position—how else could KM figure out which of the six windows you want it to activate? Even if you did something fancy to figure out which window is offset to the left/right of the current one, at some point, you're going to have to have KM activate that window either by name or mouse click.

And given that the names will be constantly changing (I would assume), then your best bet is to click in the window, and it should be very reliable, assuming that the "opposite" window is frontmost.

Here's a proof of concept using TextEdit. With two side-by-side windows open, and one of them frontmost, the macro will switch to the other via a click in the toolbar area of each window. There are probably much more efficient ways of doing this, but this method seems to work.

Download Macro(s): Window switcher.kmmacros (8.4 KB)

Macro screenshot

Macro notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System information
  • macOS 14.7
  • Keyboard Maestro v11.0.3

-rob.

1 Like

But are the two you want to switch between the frontmost two windows of your app? If so, you just need to activate the window with index 2 -- that will make it the frontmost (index 1) and your previous frontmost becomes index 2, ready for the next time you want to switch.

A single-action macro with

image

...should work in almost any app.

2 Likes

omg that's perfect and exactly what I needed :heart:

See, I knew there was a better way! :slight_smile:

-rob.