How to Use the Frontmost Application Window Dimensions as a Condition?

I created a macro to resize the frontmost application window when it activates. It is working well, but I would like the macro to work only when the frontmost application window dimensions are different from the ones when the window has been resized.

I have tried with the FrontWindowFrame token but didn't find any valuable solution.

As long as you're using the right token (%WindowFrame%1%) and the right notation, there shouldn't be any reason why this couldn't work:

Example Macro.kmmacros (2.5 KB)

Thanks @gglick.

Found the problem comes the way the macro is triggered. When I select "iTerm 2" in macro group and in macro settings, I get a yellow flag telling me the macro will not be triggered.

I moved the macro to the "Global macro group". The macro is now triggered.

The macro now has the following logic. If Window Frame 1 is 420,10,600,900 do nothing, if not, move and resize Window Frame 1 to 420,10,600,900. The macro is triggered when the application iTerm is activated.

What I do not get is that KM shows the condition is always false. If the condition is not met then the window is resized so the condition should be true then, no?

That's because you're looking at the macro in the KM editor, and the window frame token is giving you that window's frame data. If you open iTerm but keep the KM editor window visible in the background, you should see the condition change to true.

Sure I knew that. That's why I founded even weirder the condition staying the same.

But how do you explain that this macro always displays "2".

Instead of displaying 1 or 2, try displaying display the actual value of %WindowFrame%1%. That should tell you what's going on.

1 Like

@DanThomas In a separate macro that only displays the value of %WindowFrame%1% in a large text type, I get the value "270,23,900,877".

As you can see, I failed using this value to create a condition.

According to Keyboard Maestro, the value %FrontWindowSize%1% doesn't contain 270.

Setting a %WindowFrame%1% as a variable with the name "WinFrame" returned me different values (1, 23, 1435, 877).

With the values 1435 and 877, I successfully could create my condition as they both return true with the "condition operator" "contains".

I think I have found the problem:
Evidently some apps, like ITerm and Terminal, allow only certain intervals of size.
So, after I had ran this action:

image

and I ran the macro again, it still executed the action.
Why? Because the window size was actually different from the one set by the KM Action:

image

While the position 2600,200 was retained, Terminal changed the size from 1000,500 to 998,505.

So you need to get the window frame AFTER you have set it one time and display the actual frame that was set.

Here's my test macro:

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Set App Window Frame If Not As Required [Example]

-~~~ VER: 1.0    2020-11-01 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Set App Window Frame If Not As Required [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


Revised Macro

To Use Actual Frame Set by Terminal

image

Thank you. It perfectly answers the question I had.