Window Snap Utility Macro

Window_Snap.kmmacros (15.2 KB)

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.

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:
Size the window 34%W, 40%H positioned in the bottom right corner


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!


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!

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).

I am posting a newer and improved version of this macro. It does introduce breaking changes if you used the old version, so you'll need to update your calls to this macro.

Supports pixels for window dimensions and position.

You need to add a "%" to the end of previous number parameters for a percentage based size or position.

New examples:
32%,900,left,100 would make the window 32% width of the screen, 900px high, positioned left and 100px from the top.

I think it works with multiple screens (external monitors) now, although I have not extensively tested this aspect. You can add a 5th parameter with the screen index to target a specific monitor.

I hope it is useful!
Window_Snap.kmmacros (25.9 KB)

1 Like