Moving Windows

KM maps the screen coordinates as a continuous range across all of your monitors.
For example, the left edge of Screen 2 is one pixel more than the right edge of Screen 1.
So, to move a window to another monitor, you have to set it's coordinates to those within the desired monitor.

Maybe it will be more clear if I just show you. Here is my macro that moves the frontmost window from the current monitor (screen) to the other monitor.

Please feel free to ask any questions.

##Macro Library   Move Window to Other Monitor (Screen)


####DOWNLOAD:
<a class="attachment" href="/uploads/default/original/2X/a/aa4fe5267e6d9ba3083f4c80e5accdaceb75bc09.kmmacros">Move Window to Other Monitor (Screen).kmmacros</a> (18 KB)

NOTE:  The macro was uploaded DISABLED, so you will need to enable it before you can trigger it.

---

<img src="/uploads/default/original/2X/a/ab307eb8387c6b59ff2c0772fb15a631b26c8ede.png" width="466" height="1418">
1 Like

Thanks!
So conceptionally that makes sense to me, but a couple implementation questions.

  1. how do know the coordinates for my screen(s)
  2. My display arrangement is not the typical 1 screen next to the other. I have 1 34" ultrawide in Portrait mode on the left, and 2 different sized and resolutions screens next to it one atop the other.
  3. Instead of just gabbing the active window can I have it grab a specific window no matter where it is or if it is active or not? So for example when on a skpe call sometimes the little window with the picture of the other person gets hidden or moved. Can I have a keypress find it, activate it and move it to where I like it?

It's not really Keyboard Maestro that maps the screen coordinates this way, it is how the system behaves, though these days the behaviour is more confused because each monitor is now treated as its own space by default.

The origin (zero point) of the desktop is the top left corner of the main screen, which is the one with the menu bar on it in the Arrange system preferences.

If it is a real window with a known title in the front application, then you can reference it directly in Keyboard Maestro.

Otherwise you may have to resort to AppleScript.

OK. Great. Thanks.
Will fiddle with it over the weekend, but that looks great.

thanks for the clarification, @peternlewis.

@dtraub, maybe this diagnostic macro will help you deal with your screens (monitors):
Please post the results for you system/screens. I can't wait to see the coordinates of your screens.

##example Results on my Two-Monitor System

##Macro Library   Get Info on All Screens (Monitors) @Test


####DOWNLOAD:
<a class="attachment" href="/uploads/default/original/2X/5/51e33200e1b4453f3fdb25edd5669fb2dc6b6074.kmmacros">Get Info on All Screens (Monitors) @Test.kmmacros</a> (4.4 KB)


---

<img src="/uploads/default/original/2X/8/8694db1c7b357e5517c7a605bdc33ca94557299c.png" width="606" height="1331">
1 Like

I have used this to perfection on my 2 display set up but I am having a bit of a blank on how to get it working properly on my 3 display desktop setup.

My set up is 3 identical monitors which I have ordered
1 (Left), 2 (Middle), 3(Right)

I have adjusted the macro to move to the right display and left display (2 separate macros) but lets say a window is in the right most screen (3) and I hit the Move to left screen macro.

It moves the window to the left most screen (I know its because the True / False) Calculation so its working how ti should)

How can I get it to just go to the middle monitor (2) if its at the right most (3) and not skip to (1).

You should be able to use one of these parameters with the SCREEN() and SCREENVISIBLE functions :

  • 2
  • Back2
  • -1

In fact, "-1" might be a really good choice, since it should always point to the screen to the immediately LEFT of the current FrontMost screen. But I have NOT tested this.

I don't have 3 screens to test, so I can't be for sure.
You can also look at this macro:
MACRO: Move & Resize Front Window to Othere Screen (Monitor) V2 Using BACK Screen [Example]

I think I am getting tied in up the calculation here, What would you use in the first step to ID the screen

Instead of using the method I used above to ID the FrontMost Screen, here's a better method.
This macro calculates the Index of the current FrontMost Screen, which you can then use to get the coordinates of the screen on the Left (-1) or on the Right (+1).

So, if Local__ScreenFrontIndex is 3, and you want the Window moved to the screen to the immediate left of it:

IF (Local__ScreenFrontIndex > 1) 
   THEN Local__ScreenLeftIndex = Local__ScreenFrontIndex - 1
   ELSE  Local__ScreenLeftIndex = SCREENCOUNT()
END IF
Move Window to 
SCREENVISIBLE(Local__ScreenLeftIndex,Left) + 50, 
SCREENVISIBLE(Local__ScreenLeftIndex,Top) + 50 

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Get Index of Current FrontMost Screen [Example]

-~~~ VER: 1.0    2020-05-27 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Get Index of Current FrontMost Screen [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


IF (Local__ScreenFrontIndex > 1)
THEN Local__ScreenLeftIndex = Local__ScreenFrontIndex - 1
ELSE Local__ScreenLeftIndex = SCREENCOUNT()
END IF
Move Window to
SCREENVISIBLE(Local__ScreenLeftIndex,Left) + 50,
SCREENVISIBLE(Local__ScreenLeftIndex,Top) + 50

Should this be run as an applescript?

No, definitely not. Those are all pseudo KM Actions.
Actually, it is much easier to use KM to manipulate windows that it is with AppleScript.

Okay I am going to dig in a bit this evening Thank you!!

Sorry for being so dense here. I always get a little lost in KM when using Variables and / or calculations.

I'm def missing something here do you mind taking a look when you get a free moment?

Get Index.kmmacros (8.2 KB)

The main problem was that you had pasted multiple lines into the Left Coord. field of the Move Action.
After you do this, there is no indication of it containing multiple lines -- this is a bug IMO.

So, I fixed your Move Action formulas, and moved that whole IF block out of the "ID Screen Group.
I also provide a new method, which I think is more efficient, to determine the Index of the FrontMost screen.
And I gave you a couple of goodies I always use when moving windows to other screens.
You can disable/delete them if you don't like them.

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Move Window to Screen to Immediate Left of FrontMost Screen

-~~~ VER: 1.0    2020-05-27 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Move Window to Screen to Immediate Left of FrontMost Screen.kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


This is incorrect. -1 is the right-most screen. Negative numbers index the screens from right to left.

Back2 wont work to cycle through screens either, since Back2 will be the Screen 3, except when the Front screen is Screen 3, then it will be Screen 2.

Yes, this is a long standing issue with macOS and single-line fields, that it shows one line with no indication of any extra text. And yes, I should figure out a way of detecting it and showing, or just removing line breaks from such fields (and generally Keyboard Maestro does do this, just not in every single case unfortunately).

That would be very helpful.

The way the KM Wiki is worded, it is not clear what the positive and negative numbers mean when referring to a screen. I read, and reread it several times, and could never get a clear understanding.

The wiki says:

Index Name Description
Positive Calculation the indexed screen from left to right.
Negative Calculation the indexed screen from right to left.

I am open to suggested edits for it. Screens are indexed from left to right with positive numbers 1, 2, 3, and from right to left with negative numbers -1, -2, -3, so with three screens, 1 ⬄ -3, 2 ⬄ -2, 3 ⬄ -1.

The same technique is used in a few other places, line indexing windows for example.

This is PERFECT!

The cycle works great moving left! I looked at it yesterday to create a duplicate one that just moves the screens right but I couldn't figure it out.

From the other comments it looks like it should just be a number change in some of the actions but I still can't figure out which one it is! Mind giving me a hint!

By the way this community is amazing how helpful everyone is with these macros!

1 Like

Hey sorry to be a pest but could you give me a point in the right direction for what I need to update to make this work going the other direction as well (Left to right)