Window resize works inconsistently (dependent on App and Mac)

Hi guys,

I am facing an issue that has been raised already and for which there seem to be (unless I am missing it) a solution.

Resizing windows is working fine for the most part but in Google Chrome for my work machine decided to not work anymore, the same issue as described here:

I am on:
Keyboard Maestro 10.1.1
macOS 12.4
Chrome Version 103.0.5060.53 (Official Build) (arm64)

This is my work machine and it is administered by my IT, I cannot "simply" reinstall everything so I am hoping maybe some of you have an idea of what I can try specifically to fix the behaviour with Chrome?

Thanks,
Rosario

Hi Rosario,

I posted a bandaid solution I found somewhere, at some point on the forum but I can't locate it right now.

So I reposted about it here. Hope it helps in the interim.

Hello @cdthomer,

Thank you for your support, really appreciated.

Just for me to understand, I am kind of a beginner, at least when it comes to variables or scripting, what is the purpose of the Global Variable in this use case? Also, you mention in your post you use the variable along with a repeat action, how many times do you set it to repeat and why?

Thank you, just trying to wrap my head around this issue as it is pretty annoying and I want to ensure I won't bother anymore here with the same questions again and again :slight_smile:

Cheers,
Rosario

Hi Rosario,

Variables basically serve to store information on permanent or semi-permanent basis.

See this wiki entry for more information: manual:Variables [Keyboard Maestro Wiki]

So in this case I use a global variable (global essentially means permanent and globally accessible) to save just a number. Then I use the repeat action but instead of a number inside the action, I put the variable name that way it is repeated according to whatever number is stored in the variable.

The number in the variable is just however many times I've determined the action needs to repeat for the window to be properly sized. Just pick a number and experiment. Like 3 for example. If it works, great. If not, try 4 and so forth.

Let me know if you still have questions and I'd be glad to explain it further.

-Chris

Chris,

You may have already tried this, but how about an "Until" action that repeatedly manipulates the window until it's the desired size? You may have to allow a bit of "fuzziness" in the test so you don't get an endless loop when device resolution doesn't allow the window to hit exactly what you are asking for!

@Nige_S I do indeed use that method in certain macros where it is critical that the window be in a certain position. But the only way I know how to return the coordinates for a window that is in the background to be able to use them in an Until action is to use AppleScript to get position and size, then set those integers to a Keyboard Maestro variable. See the screenshot below for an example of what I'm talking about. Again this is because these windows are being resized/positioned in the background, so they are not the frontmost window and I can't use the token %WindowFrame%1%.

Using AppleScript to return a windows position and size for an Until action (click to expand/collapse)

This method is obviously more involved than a simple Repeat action using a set integer and thus why I don't recommend it since not everybody has AppleScript experience.

Perhaps you are aware of another way to return a windows size and position without it being the front window?

Hadn't spotted that -- your method of coping with background apps is very nice indeed. Only tweak I'd suggest is to feed the bounds into the AppleScript and do the looping there, which should be faster since you don't have to keep instantiating the script instance. Here's a more generalised version that allows you to pass the app name, window name, and window frame values:

1 Like

Wow that’s fantastic, I’m going to update my macro to make use of this script. Thanks for your tip!

G'ah! Forgot to rename the first two actions! Hopefully obvious that the first is to set the application name and the second the window name.

You can actually make the script more concise by testing position and size in the loop condition rather than bouncing through a variable:

tell application "System Events"
	tell application process theApp
		tell window theWindow
			repeat until (its position = targetPos) and (its size = targetSize)
				set its position to targetPos
				set its size to targetSize
			end repeat
		end tell
	end tell
end tell

@Nige_S thanks for the improved AppleScript. I made a minor change to enable using partial window names.

Also, I posted a macro here that makes use of it in case folks continue to run into this issue in the future.

KMF: Repeatedly Position a Window (For Machines That Suffer From the Window Positioning Bug) - Macro Library - Keyboard Maestro Discourse

-Chris

1 Like