Move window to next screen, and maintain its position


I'm trying to:

  1. Move a window from Screen 1 to Screen 2
  2. On Screen 2, keep the window in the same position it was (perhaps proportionally, if the resolutions are different)
  3. On Screen 2, if the resolutions are different, resize it proportionally

It seems like I'm stuck at the second point. Can anybody help me, please?

Attached below is an image that shows what I'm trying to do... But my idea could be totally wrong in the first place. :slight_smile:

Keyboard Maestro is very powerful, but it's taking me forever to build something as simple as this :frowning:


It's actually not a trivial task at all to take a rectangle within a rectangle and scale it to a rectangle within another rectangle. Keyboard Maestro has code to reposition palettes when you resize a monitor and the code runs to dozens of lines to keep the relative position in the window.

If you make the assumption that the window is entirely on screen 1 this:

Set variable W1 to %WindowFrame%Front%
Set variable S1 to %ScreenVisible%Front%
Set variable S2 to % ScreenVisible%Back%

Now we have to figure out what W2 will be.

W2.width = W1.width * S2.width/S1.width
W2.height = W1.height * S2.height/S1.height
W2.left = (W1.left - S1.left) * S2.width/S1.width + S2.left = ( - * S2.height/S1.height +

Something like this:

Move and Resize Window to Other Screen.kmmacros (2.4 KB)


Wow! Thanks a lot, Peter! It works very well. And now I also have a good example I can reuse to do other things and learn :+1:

For whoever is interested in this, I also applied an if/else condition: if just one screen is detected, do not run anything.


I was just looking for something like this and it's quite helpful. Is there a way to cycle through three displays? Using this macro will jump the window between two out of my three displays.

Take a look at this macro and see if it will work for you, or at least give you some ideas of how to do that:

MACRO: Get Next Screen [Example]

1 Like

Thank you so much for this.

1 Like

Works like a charm, thanks, my friend.

1 Like

I have just written some window move macros that might be of interest.