Using Keyboard Maestro to Custom Move and Resize Windows

Hey guys and gals! New here. I'm having a devil of a time with moving and resizing windows. I want a window to move and resize exactly as is shown in the attached screenshot, but I don't know how to determine exactly where it is x and y on the screen and how to tell KM that I want to end up there sized exactly as it is. Please help. Also, talk to me like I'm 5. I'm just getting into automation.

25%20PM|690x388

Your picture didn't come across. But here's what I'd do.

First, I'd set up a macro that has a hotkey trigger, with one action:

image

FrontWindowPosition = %FrontWindowPosition%
FrontWindowSize = %FrontWindowSize%

Bring the application window you want to manipulate to the front, and trigger the macro.

Let's say it gave you this result:

image

Then all you have to do is add a "Move Window" action:

image

and click on "Move To", and select the following option:

image

and your action will look like this:

image

Then just paste in the numbers, like this:

image

Hope that helps.

2 Likes

Dan,

That did it. Thank you SO much!

1 Like

If you don't mind, a follow up. How did you know what syntax to use in the display query? I never would have know how to do that. Is there a wiki somewhere with that info?

Yes, here's the Wiki: https://wiki.keyboardmaestro.com/Home_Page

We (those of us who answer lots of questions, or in my case, used to answer lots of questions) love it when people ask questions like yours. Sometimes it feels like people just want easy answers, and that's OK, but when someone wants to learn, well, that just makes our day. So, kudos to you, and keep asking questions! :smile:

So let me go into detail how I found this. Even though I know KM very well, even I have to dig a little sometimes. :smile:So here's what I did.

First I searched for an action that retrieved the window's position, and didn't find any.

Then I realized that there was probably a "token" for this. Tokens are awesome, but for some reason, I don't immediately look there. Anyway, I went to the Wiki, and searched for "tokens", and this is what I got:

If I had been observant, I would have picked "A", or better yet, "B", but I picked "C" which was fine, but I just wanted to point out "A" and "B" so perhaps I'd remember to look there next time. :roll_eyes:

Anyway, when I got to the list of tokens, I looked for "Window", and found what I (or you) needed.

Then I wondered how to display the information, and at first I was just going to use a regular "Prompt for Input" action, but I decided it would be better to be able to copy the values, and I knew there was some sort of "Display" action that displayed text in a window.

So I searched for "Display" and got this:

image

Even though it said "Display text briefly", I noticed the menu button (arrow), so I figured this had what I wanted. And sure enough, when I added the action and popped up the menu, there it was:

image

Then I messed around displaying various Window tokens until I thought I had what would work best.

Then I searched for a Window action, and got this:

image

Even though this didn't show changing the position, I saw this one did:

And I figured the popup menu would have the action I wanted, and it did, after a little poking around:

image

And that's the thing about KM. There's SO MANY things it can do, you can't possibly know everything. I'll bet even Peter (the guy who wrote KM) doesn't even remember everything it does.

So when I'm stuck, I search the Wiki, and this forum, and I usually find the answer pretty quickly. I also periodically just skim this forum, looking for interesting topics. I learn new things all the time that way.

Anyway, enough of this novel, and have fun! Keep learning, and asking good questions like this.

2 Likes

You're very helpful, Dan! I really appreciate it!

1 Like

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

Hi @twijit, welcome to Keyboard Maestro (KM) and its Forum.

KM is one of the best Mac automation tools available, its Forum is one of the best and friendliest forums on the Internet. Whenever you reach a tough stumbling block trying to use KM, please feel free to post your question/problem here for help.

You will also find this helpful:
Tip: How Do I Get The Best Answer in the Shortest Time?

Getting Started with Keyboard Maestro

For more help, see Getting Started with Keyboard Maestro and the Forum .

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

1 Like

Thanks JM!

Definitely - more than once I've gone to say "there is no way to do that" and found someone else had found a way I'd forgotten about.

1 Like

Thank you for this, Dan! I had the same question as twijit and just used this approach successfully. Much much much appreciated!

FYI.

I recently made the jump to Catalina and found that on my three screen set up there are new menu items in the window menu.

Move (to screen x)
Move (to screen y)

I renamed my screens so the left and right screens are named "Left" and "Right" and then I just use KM to call the menu item in the window menu to move the currently frontmost window to that respective screen.

I know this is not what you where trying to do per se, but hoping it helps others.

1 Like