How to Change the Window Position?

I'm trying to move a window back and forth between two positions while minimizing another window.

The beginning of the macro works, but I don't know how to finish it correctly.

It should end like this

If the window "Scrivener DB Notes" is already in position A, then move it to position B. Can someone help? Thanks!

Scrivener DB NOTES.kmmacros (6.8 KB)

You could use the window position token to test the current position, and then move it to the other.

Do you want to activate that window, or only move it? Do you always want to minimise "MASTER", or only in one of the two cases?

What do you want to do if it isn't already in position A -- put it there?

Hi Nige, thanks for helping :slightly_smiling_face:

The "NOTES" window is always open and always the same size. It is supposed to be activated, but it only changes the position from A to B or from B to A. There are no other positions.

The "MASTER" window should always be minimized when the "NOTES" window is in position A. What it does otherwise does not matter.

Maybe it needs what devoy suggests. But there are only two positions. So, a kind of cycle action seems more logical to me.

Which makes everything easier because you know it will be there, can activate it so it is window 1 (and don't have to search for it) and, as you say:

if position is A then
   move to B
else
   move to A
   minimise "MASTER"
endif

Bringing a window of an app to the front will also activate the app, so we can dispense with that action. So, adding a pause and assuming that what you've marked "position A" is position A and not the place to move to when it is found in position A:

Scrivener DB NOTES v1.kmmacros (6.2 KB)

Image

But the condition in that macro is horribly precise -- the window need only be in position A but out by one pixel in any dimension for it to be moved to "true" position A instead of B. So it might be better to be more fuzzy -- an obvious choice would be something like "If left edge is less than 2400", then if it is near A it will move to B and vice versa:

Scrivener DB NOTES v2.kmmacros (6.1 KB)

Image

Note: Not having Scrivener I've used Finder for the app in the first action in both macros, so you'll need to correct that.

Thanks Nige, but your macros do unpredictable things. Always something different. :joy: Most of the time the "Notes" window is activated (in position A) but nothing happens after that. Sometimes KM shows an error message that the "Master" window was not found. :man_shrugging:

Try making two new folders in the Finder, "Scrivener DB NOTES" and "Scrivener DB MASTER", opening them both, and running the v2 macro without alteration (so it targets the Finder with the first action) with Finder frontmost. It behaves impeccably for me -- does it for you?

If so, try starting the macro with an "Activate Scrivener", and change any references to Finder to Scrivener as well. I know I said it wasn't needed but I think I was wrong -- missing it out means only the targeted window moves in front of other apps and the rest may stay hidden.

I don't know your setup but I went with the pixel values you gave -- on my 5K iMac they put the "NOTES" window mostly off-screen. You may be running into the sometimes-reported issue where, when a move-and-resize will result in a window coordinate being outside the screen boundaries, the operation is only partially done.

If you can confirm your screen size and the coordinates given, I'll see if I can download a trip of Scrivener -- KM not finding a Scrivener window that you know is there seems to point to an app, or maybe timing, problem.

You are right, I have tried this with several other apps, eg with TextEdit. Your macro works perfectly for any other app. Unfortunately not in Scrivener. Mmm, then this is a problem with this app.

Whatever, thanks anyway, Nige! In the meantime, I have found a good solution with BTT. One little thing still does not work as in KM. But maybe I will find a way. :grinning:

Is the window you're trying to manipulate a floating window or otherwise out of the ordinary?

Keep in mind that Keyboard Maestro does not see all window types, and you have to check.

1 Like

Thanks @ccstone but it is not a floating window. The error must be somewhere else.

There's something funky going on with Scrivener's window names. Try changing the window name conditions to "title matching" ("Bring window to front" action) or "title matches" ("Pause" action).

That's got it working 100% for me, while using "contains" was broken -- even when copying the names from the results of %WindowName%All%. Weird!