Arrange two windows chosen by mouse clicks

Is there a way to size and arrange the last two windows that have been selected by mouse clicks - whether they are from the same app or two different apps using a single macro with one hot key combination?
I have been able to make a simple macro that does this for two windows from a single app. And a second macro that does this if the windows are from two different apps. But I would like to have a single macro with one hot key rather than having two macros with two hot keys.
Any help much appreciated.
These are the original two macros that I would like to combine into one (depending on which two windows the mouse is last clicked on):
Tile 1 App 2 Windows.kmmacros (2.9 KB)
Tile 2 Apps 2 Windows.kmmacros (3.1 KB)
Tile%201%20App%202%20Windows
Tile%202%20Apps%202%20Windows

You can easily address all windows for the frontmost app, but it can't be done with native KM Actions/Functions across apps. You might be able to use AppleScript to do that.

You might consider this tool:
Moom window management Tool

It makes window management real easy. You might be able to do most of the stuff it does by building a lot KM Macros and AppleScripts, but it would take a lot of work.

The only way I know of to do this in KM is:

  1. Create Macro that is triggered by a change in window
    • Record the window data to a global KM Variable
    • Store the most recent window at the top of the list
  2. Create Macro to arrange windows

Hey Mark,

That's a very sticky wicket.

In my opinion you're better off using two macros.

-Chris

Hi all - thanks very much for the help. I am trying to implement JMichaelTX's suggestion of two related macros.

Create Macro that is triggered by a change in window
Record the window data to a global KM Variable 1
Store the most recent window at the top of the list

Create Macro to arrange windows
Get top two windows from the global KM Variable
Use the Manipulate a Window action as needed

But I don't know quite how to do this. This is my attempt so far (which I know is wrong):


I'm sure I shouldn't have to use the clipboard and also, the Move and Resize action insists on referring to the "Front Application" - I don't know how to get it to refer to the stored names of the last two windows.

I have managed to come up with a solution that suits my working needs. I realised that there are currently only two situations I use this tiling windows in at the moment. If I am in the Finder, it's the last two Finder windows I want to tile. And if I'm in any other application it's one window from each of the last two applications I've clicked on - so that might be Preview and Safari for example.

So, I used Keyboard Maestro's "If Then Else" Control Flow Action to make the same macro behave differently depending on whether the Finder is the last application I clicked my mouse on.

This is not quite the perfect solution I was searching for as it is very specific to my current working needs (rather than any two last windows chosen) but it does mean I have one macro and one hot key to do both which is what I was aiming for.

Here is the macro I made:
Tile Two WIndows.kmmacros (6.1 KB)

Hey Mark,

You can determine the index order of applications.

Show running apps by index order macro

So you can adjust the frontmost app's front window in real time and app 2's window in the background without bringing it to the fore.

Manage Front Window in Apps 1 and 2 (Special-case Finder).kmmacros (6.4 KB)

The AppleScript may look a bit complicated, but it's pretty straightforward once you wrap your head around it.

You can do some pretty sophisticated stuff using this general technique.

-Chris

Thanks - that's a great bit of AppleScript. I will play around with it.

By the way, I am using on a daily basis the Macro you kindly made for me for saving screenshots to the clipboard and simultaneously to a file. So, thank you again for that.