Behavioral difference moving a window using "Front" vs "Back"

[Please see macro screenshots for better clarity]

I created a macro which resizes a window to 33% of the screen using SCREENVISIBLE(Front,Left)*66.667% and moves it to 33% from the left edge of the screen using SCREENVISIBLE(Front,Width)*33.334%. I also tried to create another other macro which does the exact same thing but also moves the window to my opposite screen using SCREENVISIBLE(Back,Left)*66.667%

Both macros only work on my main screen, whether or not I use the Front or Back index. If either macro is used on my second screen, it only places the window at the left-most edge.

Do I have a syntax error somewhere?

Front Window Back Window

not sure if this helps, but

see WindowDual: Move and Resize windows with one or two screens

explanation on screenvisible

Thanks for your reply.

I'm having some trouble intuiting the explanation you provided and the how it applies to the Front / Back issue I'm having. I have a feeling the issue is stemming from the fact one screen's coordinates are a positive number and the other's are negative. But I'm calculating their size and position with percentages, so do positive/negative numbers even matter?

Do you have an idea why the macro only works on one screen and not the other?

For more context, my main screen is on the right and the second screen is on the left. The left screen's coordinates are being reported in negative coordinates and the right's are positive.

Thanks for the help.

It would be best if you could clearly state your object of the KM Macro you want to build.

In the meantime, please review the differences between "Front" and "Back" in this KM Wiki article: SCREEN function.

I think most of the time you will want to use "Front".

Thanks for your reply.

I have two screens and my goal is to have two macros. The first will resize the frontmost window to 33% of the size of the screen and position it 33% from the left side of the screen containing the window. The second macro will resize the frontmost window to 33% of the size of the screen and position it on the other screen 33% from the left edge.

For some reason, neither macro works as they should on my main (right) screen [see original post attachments] (I incorrectly stated in my previous post that it was only working on my main screen). It resizes the window correctly, but only places it at the left edge of the screen.

As far as I can tell, I'm using the Back index correctly. But I'm not getting the right positioning behavior on my main screen regardless of where I program the macro to position the window.

Any thoughts?

This can definitely be done in KM. Please upload your macro so we can see what you are doing.
I see no reason to use "Back".

IAC, here is an example macro:

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 & Resize Front Window to Othere Screen (Monitor) [Example]

-~~~ VER: 1.0    2020-05-08 ~~~
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 & Resize Front Window to Othere Screen (Monitor) [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


Your macro worked! Thank you! I streamlined it a bit with the inclusion of Back which seems to be working so far. I wasn't including math you included in the first move field:

working macro

Can you explain why using only SCREEN(Back, Left) * 66% in the first move field doesn't work?

I'll let someone else explain the "Back" parameter. I've written many window/screen macros, and have never found a use for it.

1: i suggest you put a screenshot of your screen layout i.e. sys prefs>displays>arrangement
2: give the pixel size of your two screens
3: include some debug code so you know the value of the calculations
i.e. do NOT do calculatioin as part of the params for SCREENVISIBLE, then aat least you know what they are
4:display value of all variables in a display text in window action i.e.height, width etc

Hi, Jonathon.

Thanks for the reply.

  1. I've attached a screenshot of my Monitors arrangement.
  2. Both monitors are 2048x1152 and are identical models.
  3. No debug code to speak of. Just the strange behavior of the SCREEN(Back,Left)*33.334% not working without the addition of (SCREEN(Front, Width)*x.x%). [see my last post attachment]
  4. No variables used

The big mystery is why the SCREEN([Front or Back],Left)*33.334% works on the Right screen and not on the Left.

Any ideas?

monitor arrangement

I have two screens and my goal is to have two macros. The first will resize the frontmost window to 33% of the size of the screen and position it 33% from the left side of the screen containing the window. The second macro will resize the frontmost window to 33% of the size of the screen and position it on the other screen 33% from the left edge.

Assume the value is negative, then for Back left you might like to try

instead of SCREEN(Back,Left)*33.334%

try

SCREEN(Back,Left) + SCREEN(Back,Width)*33.334%

You may also may need to make the same sort of amendment for the Front screen logiv in case you should ever move your screens around.

Thanks for asking this question about SCREEN "Back".
Sorry I dismissed it too quickly at first.

After some investigating and testing, here is what I have learned:

Assume that you have two screens, placed as follows:
[SCREEN 1][SCREEN 2]

Then we can make good use of the "Back" parameter of the SCREEN Function [KM Wiki] .

" Back -- the first from the left not containing (the most of) the front window."

What is not clear, is that if the Front Most Screen is the Left Most Screen (Screen 1), then "Back" will refer to Screen 2.

So this makes toggling the movement between screens very easy. Regardless of which Screen is Front Most, the SCREEN "Back" will always refer to the other Screen.

Here's my simple example which illustrates this.

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 & Resize Front Window to Othere Screen (Monitor) V2 Using BACK Screen [Example]

-~~~ VER: 2.0    2020-05-10 ~~~
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 & Resize Front Window to Othere Screen (Monitor) V2 Using BACK Screen [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


ReleaseNotes

Author.@JMichaelTX

PURPOSE:

  • Move Front Most Window to Other Screen
    • Makes use of the SCREEN(Back, ) Function

HOW TO USE

  1. First, make sure you have followed instructions in the Macro Setup below.
  2. Trigger this macro.

MACRO SETUP

  • Carefully review the Release Notes and the Macro Actions
    • Make sure you understand what the Macro will do.
    • You are responsible for running the Macro, not me. ??
      .
      .
      Make These Changes to this Macro
  1. Assign a Trigger to this macro.
  2. Move this macro to a Macro Group that is only Active when you need this Macro.
  3. ENABLE this Macro, and the Macro Group it is in.
    .
  • REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:
    (all shown in the magenta color)
    • CHANGE to the Percent of Screen to Resize The Window to

REQUIRES:

  1. KM 9.0+ (may work in KM 8.2+ in some cases)
  2. macOS 10.11.6 (El Capitan)+

TAGS: @Window @Screen @Back @Example

USER SETTINGS:

  • Any Action in magenta color is designed to be changed by end-user

ACTION COLOR CODES

  • To facilitate the reading, customizing, and maintenance of this macro,
    key Actions are colored as follows:
  • GREEN -- Key Comments designed to highlight main sections of macro
  • MAGENTA -- Actions designed to be customized by user
  • YELLOW -- Primary Actions (usually the main purpose of the macro)
  • ORANGE -- Actions that permanently destroy Variables or Clipboards,
    OR IF/THEN and PAUSE Actions

USE AT YOUR OWN RISK

  • While I have given this a modest amount of testing, and to the best of my knowledge will do no harm, I cannot guarantee it.
  • If you have any doubts or questions:
    • Ask first
    • Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.

I understand what the Back function is for and when to use it. And your first solution worked replacing your variables with Back. This macro works as expected:

Screen Shot 2020-05-10 at 4.22.21 PM

My issue is why does the macro only work on the Left screen and not the Right (Main) using Front or Back when coded this way: SCREEN(Back, Left) * 33% ?

And why do I need the inclusion of the second expression of SCREEN(Back, Left) + (SCREEN(Back, Width) * 33.334%) to make the windows behave as expected? Wouldn't SCREEN(Back, Left) * 33% give the function all the necessary parameters?

The answer is yes, but probably not the figures or place you wanted.

Imagine you have two screens.
The one on the left we call Lenny
The one on the right we call Roger.
In prefs>display> arrange, Roger is the primary screen as he has the white menu bar at the top.

The physical dimensions of Len and Roger will not change so the
Values of SCREEN( Len or Roger, height or width) will be constant

THE TOP LEFT CORNER OF ROGER has x,y coords of 0,0 !!!!

If we want to put a window on Len, then we start at 0,0
Go left for the width of Len, and
Then come back how much we want towards Roger in your case 33%.

So we have starting at coords Screen( Len, Left) for the left hand edge of Len
Then come back 33% width of screen,
So add Screen(Len, width) x 33%.

Giving SCREEN(Back, Left) + (SCREEN(Back, Width) * 33.334%).

For the right hand screen, the left edge of Roger is zero, so for example Screen(Roger, Width) x 33% is OK BUT ....

If you move active menu bar to Len, then you will need for Roger the same logic
i.e. SCREEN(Roger, Left) + (SCREEN(Roger, Width) * 33.334%), as 0,0 is now top left corner of Len, and you need to align on the left hand edge of Roger.

Similar logic applies if the arrangement is one screen higher than the other or offset to the other.

If you will do the calculations manually, and examine the numbers, then it should become clear. Remember that screen coordinates are contineous starting with the left most screen at 0,0 and increasing as you move right. So the right screen starts at 2560, in my case.

Create a Display in Window Action and add all of the various Screen tokens you need to understand the system.

Apologies for not getting back to you sooner. Thank you so much for your help. Your explanation is very helpful and eye-opening.

Thank you so much for the help. The math is beginning to make sense to me now. The idea I was multiplying a number by "0" and expecting something else other than "0" is a little ridiculous. :confused: