I'm trying to:
Move a window from
Screen 1 to Screen 2
Screen 2, keep the window in the same position it was (perhaps proportionally, if the resolutions are different) 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.
Keyboard Maestro is very powerful, but it's taking me
forever to build something as simple as this
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
W2.top = (W1.top - S1.top) * S2.height/S1.height + S2.top
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
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:
Thank you so much for this.
Works like a charm, thanks, my friend.
I have just written some window move macros that might be of interest.
This sets of macros is designed mainly to work with TWO screens, an INTERNAL screen on you macbook and an EXTERNAL Monitor. If you have more than two screens, the macros can be adapted. See Keyboard Maestro wiki for Screenvisible parameters.
However, all the macros will work if you ONLY HAVE ONE SCREEN. Some actions will not make sense but some e.g. almost maximise screen will work fine on just the internal.
I repeat they will work with ONE or TWO screens, maybe more.
The version ha…