Window Snap Utility Macro

Window_Snap.kmmacros (15.2 KB)
Hello!

Attached is a macro I have found very useful for window size and position management. There is one bug (or bug with KM) that I will detail at the bottom.

Usage:
Execute macro action with parameters width,height,positionX,positionY,screenIndex

  • width & height are a number that represents the percentage of total screen dimension
  • positionX can be left, right or center text values or a percentage number
  • positionY can be top, bottom text values or a percentage number
  • ScreenIndex (not required) is the KM index which runs left to right.

So these sets of parameters would do the following:
image
Size the window 34%W, 40%H positioned in the bottom right corner

image

Size the window 32%W, 100%H positioned on the left on the "main" screen

The bug is when you have multiple monitors set up. It seems KM calculates menubars twice when it's a vertical alignment. As you see my setup, the bottom right corner will size too tall.The bug shows up different ways depending which display is designated the main display in MacOS. If you see something I can do in the macro to make this behave properly, let me know!

1 Like

Your Y coordinate settings relate to the Main screen, not the selected screen.

That is why they are off on your second screen.

1 Like

You are right, that this was an error. I changed out "Main" for local_ScreenIndex in the section you referenced. The original "bug" still remains. I think it has to do with MacOS. If I arrange the displays to have my secondary on the side, it works perfectly. And it only screws up on windows that are in the vertical path of the lower monitor when it's positioned as described. Thanks for the improvement suggestion!
Xnip2022-07-27_09-23-05

If you are still having an issue, post your corrected macro and explain the issue.

Even on the second monitor, there is a menubar (at least for me there is, it might be a settings issue). Thus the SCREENVISIBLE function for the second monitor returns the area excluding the menu bar and the dock (the area is provided by the system API, so it is not something Keyboard Maestro calculates itself).