Position an application window in a specific location on my screen

It could be that I’m just not aware of which macro to use for something like this, but I have a program that runs every time I boot up (memory diag). I like to have the preferences window open while my computer is running so that I can toggle the automatic recycle button on and off as needed. Ths issue is just that I would like to have it placed at a specific location on my screen. I just do it manually, but it would really be amazing to have some sort of macro that would automatically place it (drag and drop it?) where I would like it exactly on the screen.

What would be the best way to do this? Is this possible?

Dragging windows around is something KM is very good at. But you have to get more specific. First of all, I can’t test the app, since I’m not going to install that app because it’s privacy statement says that when you run it, it will send your email address back to corporate HQ, and the company is registered in a tiny island nation, probably to prevent anyone from knowing where the developers are actually located. But I’m willing to help you fix your problem, if you provide more details. Does the app appear on the same position on the screen each time? If so, you can probably just use a single KM action to drag and drop the window to the location that you want.

And depending on which version of macOS you have, this may be even easier, since recent versions of macOS have keyboard shortcuts that move windows to specific locations on the screen. Perhaps you aren’t aware of this. So you may not even need to use the mouse at all, just a keystroke. Have you looked into the keyboard shortcuts for window placement for macOS apps?

Thanks for your fast response. I would imagine that this could be tested on a more neutral app so as to be able to give me some context? I also created a short screen video outlining what I’m hoping to automate. Is that sort of thing helpful? *should be able to play in browser without needing to download.

I mentioned the "Manipulate a Window" Action in your other thread -- have you tried that? Whether it works will depend on the preferences window being a "proper" window that Keyboard Maestro can target.

In general, don't use KM to replicate mouse clicks and drags if you can use a KM Action to do what you want. Your macros will be much more robust if you try to do things "programmatically" rather than trying to exactly replicate what you as a user would do.

I did, thank you! I’m experimenting with it right as we speak. In this case, however, I don’t necessarily need to resize it (different from the other issue I had posted in the other thread) but would just like to relocate it to a specific place in my screen.

I could be mistaken but I’m not seeing anywhere on the Manipulate A Window option to do this, only resizing it….

Ok, i did manage to find the “move to” option, but I’m not sure exactly how to determine the exact “pixel position” (?) of where it needs to be. Is there a way to somehow automatically detect where I’ve placed it so as to have the coordinates detemined?

Go to Keyboard Maestro and select "Mouse Display" from the "Window" menu. You can then see the coordinates of your pointer relative to the various "anchors" you can choose in the KM Actions:

See also this part of the KM Manual.

You can also position the window how you want then run a macro with a single Action:

...to display the window's values.

I can help you find where it is, probably using Find Image, but you are the one that has to tell me where it needs to be. I don’t know where you want it to go. In your video you said, “I’d love to move it at/on a specific window.” I don’t know what that means. Where do you want it to go?

Thank you, @Nige_S for showing me how to locate the pixel position.

@DocOck I am happy to elaborate.

When I open the program (MemoryDiag), and then open the preference window (the one that I want to have open on the desktop) it opens up at a random spot each time. It’s never uniform. Sometimes if opens on the left of my front monitor, other times it opens on the right side of my top monitor. It never opens in the same place.

For context, this is what it looks like:

What I would like to do is to move this to an exact location on my right monitor, so that it fits snuggly in between a few other windows, like so:

.

Okay. So that means you KNOW the exact coordinates of its destination. That means you can use a simple Click and Move Mouse action to drag the window from its current location to its destination location. What you need to do now is find its current location. That’s not hard. The problem is that this doesn’t look like a well-behaved macOS window. It’s probably a special window that doesn’t show up to the same actions as normal windows do. Therefore, I think the only way to find its current location is to use the KM Find Image action to find its location. The main thing to do is decide what bitmap you will use to “find” it on the screen. When I look at the image, it seems fairly safe to search for the three icons at the top of the window. So your action will look something like this:

The black rectangle inside the image box is a screen capture of the three buttons at the top of your window. I think this action will work quite reliably for you. Then the next step is to drag the window using an action that will look something like this:

Also, the last piece of the puzzle is to get the window to appear. Is the only way to do that to click on the system menu? If so, you will need to click on the menu, which we can also find with another Find Image action, or with absolute coordinates. You should check if there’s a keyboard shortcut to activate that window first.

Thank you for this. I think I’m a little confused, however. I ask for your patience, as this sort of thing is very difficult for me and I am not as experienced as you are.

The preferences window (the one in the screenshot that I sent to you) appears by default when you open the program. It’s appearing is not the issue. Automating a macro to drag it / place it where I would like to be placed without having to manually do it each time is what I’m trying to figure out how to do.

It appears randomly on different parts of the screen. With that in mind, I do understand that Find Image macro. What I’m getting confused on is what to do from there. Speciically, I don’t understand what is happening on the second screen that you sent me or how this solves the problem (Move and Click and Drag at).

And please be patient with me. I’m not a perfect teacher.

That’s not quite true. The program is already running. You are just telling the program to open a window when you click on the icon in the system menu.

That is done using the Move action which I showed you in my last post. The action I gave you takes two sets of coordinates. The first set will contain the values that I showed you (Local3Button.x, etc.) and the destination coordinates will be determine by you using the method that Nige illustrated to you above.

Did you check your app’s manual to see if there’s a keyboard shortcut for opening its preferences window?

Immediately after your Find Image action you place your own version of the Move action which I showed above, using the coordinates that I’m explaining to you in this post.

Ahh, that may be your problem. There are no “screens” to worry about. All your screens share the same coordinate SYSTEM. Every screen should have (as far as I know) unique coordinate numbers. So there’s no concept of a “screen” in terms of the solution I’m giving you. Just “x,y” coordinates.

Again -- don't do this unless you have to!

And you don't.

Change the numbers in the third Action of this macro to where you want the top-left corner of the window to be positioned, set the hot key trigger to the key-binding of your choice, and you're done.

Position Memory Diag Prefs.kmmacros (3.0 KB)

Take a look at the macro, use each Action's "Help" item in its "Settings" menu to see how it works -- and ask questions if anything isn't clear.

Nige’s advice is better than mine, although my advice isn’t wrong per se. His way looks easier.

Now we’re getting somewhere! This is so much easier to understand and follow! Thank you.

Alrighty….so I think the last phase of this is trying to get it to appear on the correct monitor. I have no less than 6. Yes, I use them all, and yes, I need them all. That being said, while I have the measurement dialed in of where it’s supposed to go, it seems to only appear on my central monitor. How do I get it to move to the monitor to correct monitor?

If it’s helpful, here is a list of all of the default names of them. The name of the screen that I would like for this to appear on is “LG SDQHD” located on the right.

Note that I did try a few of the options in the drop down menu “front windwo, window named, etc”. But it didn’t appear to correspond with any of these.

Screen names don't matter.

How are you getting the numbers to position the window? Both options I showed you will return "absolute coordinates", where 0,0 is the top-left corner of your main monitor, and those numbers should put the window in the correct place.

You can position it by coordinates based on a certain screen -- but that involves a lot of, in this case unnecessary, maths!

These refer to the window you are moving, not the screen. There is only one window, so it will be the one at the front.

Once again, this is the issue that you don’t seem to understand yet. There are NO monitors to specify when using screen coordinates. All monitors use a single coordinate system. Use the utility that Nige illustrated, and check for yourself. Look closely how every monitor has unique screen coordinates. There is no overlap of coordinates.

That’s what I think is the case. I have only one display so I can’t test it.

To obtain the numbers to position the window, I’m using the method that you showed me.

These coordinates are in fact positioning the window in the main monitor / screen (ie, the one named C49RG9x in the screenshot of the arrangement of my monitors).

What I would like to do is move it to another monitor / screen. Not somewhere in the main monitor / screen. Specifically, the one named LG SDQHD (located on the right in my arrangement).

By jove! I see what you’re saying. Now I understand. I had it in mind that it was showing the coordinates per monitor. Makes sense!

Alright…..now it’s working.

For clarification, the number located in the coordinates is the top left portion of the window being moved? That appears to be the case on this end.

To be accurate, they are the top of the window and the left of the window -- together they define the top-left corner. Worth being pedantic because "left" and "top" (along with "width" and "height") crop up in many KM Actions, Tokens, and Functions.