Way to Resize an iOS App Running on macOS

resize window.kmmacros (2.9 KB)

Okay so for context, I'm trying to create an automation for a game that I play on my phone. Thanks to my M1 MacBook, I can open and play the game just fine on my Mac, but every time I open it the size of it changes. I tried the resize window action, but I can't get it to resize the game window. It works just fine for Safari etc, but not the game. Anyone else have an Idea? I tried doing it with AppleScript, but since I'm a novice at that, I can't seem, to get it to work. I need to have the game play at the same size every time, and preferably completely without me resizing it manually (e.g full screen, since the screen size of could change, which would mean re-doing the whole macro).

Thanks a lot!

Howdy, welcome to the forum! As you might have already figured out, this is a great community full of people who love to help.

If possible, post the macro itself so we can take a look at it and see what might be going wrong. As one of the moderators likes to say, "If we're not testing we're guessing, and guessing often wastes people's valuable time". :laughing: If you need help on how to post the macro, just let us know and we can walk you through it.

If you haven’t had the opportunity to read this tutorial, I highly recommend it. It will help you get the most help for your question.

Tip: How Do I Get The Best Answer in the Shortest Time?


hey, thanks for the reply. I added both an image and the Macro file ( I think) I'm still new to KeyboardMaestro, still learning :slight_smile:

Are you able to resize the window with your mouse? Some apps prevent resizing. If you can't do it with your mouse, you may not be able to do it with KM.

Should I infer from that that you are able to resize it manually?

What does resizing the screen have to do with resizing the app? Are you trying to make the app a certain absolute size, or a certain relative size to the size of your screen?

In your sample code you are trying to resize it to 125 by 125. That's the number of pixels, not percent. Most apps can't be resize that small, including the KM Editor. That could be your problem. If you can determine how many pixels you want to resize to, then put that number into that action. Or try 1000 by 800 for starters.

I cannot resize it with my mouse. I thought so too. The thing is, double clicking on the window outline changes it’s size. Also when it’s open, and the dock isn’t there, it’s bigger. As soon as I move my mouse to the dock, it changes size. So there is a way to change its size.

Those are important clues. I'm not sure yet whether it's resizable. Try this... when the program is active, see if, under the Window Menu, you see an option called Tile Window to Left of Screen. See what happens there.

P.S. Just because MacOS can resize it, that doesn't mean the user can.

Also, I just tried random numbers, nothing worked. Also tried the exact resolution that my phone runs the game at, because I thought it might only work for a certain format.
My point is, that my macro is working off the coordinates in the window, I can’t do it all with image detection (at least I don’t think)

maybe there is a way to calculate the width and height of the window, and change the values in the certain actions by calculating the difference? Idk

If your random numbers were all below 200, I wouldn't expect it to work. Did you try my recommendation of 1000 by 800?

What do you mean "my macro is working off the coordinates in the window"? Have you already written a macro? I thought you couldn't write your macro because you couldn't get the window the needed size. I'm unable to see the big picture here.

okay I‘m sorry, let me redo this.

I have made a macro, that does daily task on this game. It works off mouseclicks at certain coordinates from the top left corner of the window. My macro works, if I use it while maximizing the game on my macbook screen.

My Guildmates have asked me about the macro, and I noticed, it might be useful to more people than me. When trying to share it though, I noticed when someone had a different sized screen, it won’t work, as for example a button, that on my screen is at 200x200y, would be at a different coordinate for them.

So now I want to add a action before the whole macro that makes the window a specific size, so that it’s the same on every machine.

tile to left side of the screen works perfectly.

That's a bit clearer. So you say that the macro currently works "while maximizing the game on your MacBook screen". Now you want to modify the macro to work on your Mac in non-full screen mode so that, you hope, it will then be portable to different Macs with different screens.

That's a reasonable request. Please allow me to ask for a third time: can you resize the window to 1000 x 800?

Actually, I don't see why having a different sized screen would have any bearing on the mouse coordinates inside the window. Regardless if the screen is 800x600 or 1024x768 or 2000x1500, or any other size, the number of pixels rightwards and pixels downwards within the app would always remain identical. That is, assuming that the app is NOT in full screen mode, which you seem to be saying you are trying to modify your program to work in.

P.S. When I write code to play games, I always made an effort to make my app independent of screen resolution. One way to do this (not the only way) is to use Find Image to find the location of the button you want to click on. Have you considered this approach?

I have tied it just now. Something very weird happens.

now the window changes position, I am not sure if that is 1000x800 though. I have uploaded it here:


Thanks for showing that video. Now I see that the window is already (appears to be) at the maximum vertical size. Are you trying to make it smaller, I presume? Or were you trying to make it bigger?

This app most likely has a fixed aspect ratio. (Not necessarily a fixed size.) And since you said you cannot resize it with the mouse, then it may also have a fixed size. I presume you were trying to shrink the window when you were using the mouse to resize it. Is that correct? Or were you trying to make it bigger?

At this point maybe it's safe to assume that MacOS is not allowing you to resize the window, even though MacOS is itself resizing the window from time to time. In that case, I think the best thing for you to do is stop using absolute mouse coordinates and start using something else. While Find Image is a very easy and reliable method, it probably won't work in your case because you are worried about different window sizes. The KM Find Image action doesn't adapt well to changing window sizes. You were thinking about "scaling" the numbers for different sized windows. I wouldn't recommend scaling; what I recommend is using "percent values". So for example, if you want to click on that red hammer on the left side of the screen, you should call a subroutine that looks like this: (at first glance, it looks like the icon is 5% across the image and 25% down the image)


Doing this would most likely make your app portable.

You would implement the above macro something like this:

Notice that the word "something" appears four times in this image. That represents a calculation which I didn't want to calculate for you right now. Basically, it just takes into account the width/height of the window and its base position. I do this sort of thing all the time.

What do you think about this idea? If you don't like it, there may be other options. I know you want your macro to be portable without making any changes, but if you can't resize the window at will, then you may need to make changes. And in my mind, my suggestion here is the simplest way to adapt your program with minimum effort and maximum portability. How much code are we talking about? 100 lines? 1000? 10,000?

Hey, first of all - Thank you for that amazing answer! Thank you for putting the effort in to help me. I appreciate that.

when I tried resizing it, I just tried to live it’s boundaries (as in trying to change the window‘s size by dragging at the corner) and that didn’t work.

I did not know that you could click at a percentage of the App. That’s good, as it would work on any size. ( at least I think so, as long as aspect ratio stays the same ). I‘m going to check that out later.

as for the amount of code, it’s not that bad. it’s like 20 lines right now, as I‘m just starting it. I will try your suggestion and see how I would do it.
How do I know at what percent the button is tho? Since now I have been using the „get“ button to get the coordinates.
again, tysm. for the effort!

You need to find and launch the utility on MacOS called "Digital Colour Meter." In its window it shows you the position of the pointer in the screen, and more.

Well, the only reason I can do it in my example above is that I created a subroutine that does the math that converts percentages to absolute values.

I agree. It seems to be the best solution for you. But I don't think it depends upon the aspect ratio being constant because if you stretched the window, the percentages should still work. What it does depend on, and I didn't mention this yet, is whether there are any solid colour borders in the app at any time. I'm worried about that, but we can deal with it if it comes to that.

My Color Meter looks like this:

I got the cursors position by Command+shift+4, that works I think.

Click Percent .kmmacros (2.1 KB)

This is the Subroutine that I created. The values that I added as something are the bottom right corner, when my window is aligned like this.

Then I made this macro, that calls the subroutine:
Click test.kmmacros (2.6 KB)

I does work. Putting in a value of 90/90 clicks about where I think it would. (almost bottom right corner).
Then I tried resizing the window, as I moved it to my 2nd screen which has a higher resolution.
Now my Screen looks like this:

Now though, the 90% dont work anymore. So I got the new coordinates, and changed the values in the subroutine. That made it work again. Quite happy so far.

But then I tried hitting a specific place in the app, and that took me many tries to get right. finding the correct % that it needs clicking at, was a trial and error for me. I guess there is an easier way to do it (now that I'm thinking of it, knowing where I want to click, I can just reverse do the math?)
That's going to make creating the Macro a lot more tedious. Still thinking of a way to make that easier.

There are, the UI has a lot of sharp borders. But I am not sure why that would be a problem? maybe I am doing something wrong, but I dont see the problem yet.

But with your method it is, kinda portable. For a different resolution one would only need to change the values in the calculation, if I'm not mistaken.

It looks like you don't have the colour meter's "Show Mouse Location" flag turned on under the View Menu. That will help you. You do not have to hit CMD-SHIFT-4, but if you like doing that, that's fine.

It sounds like you are happy with your results. But I believe you are doing something wrong. Do you remember in my screenshot I had the word "something" as a multiplier and an additive to the X and Y coordinates? You've adapted that idea by putting constants in there, but that's a mistake, because you should be putting functions in there. That's because you want to be able to account for a dynamic location and size of the window. There are functions in KM that allow you to get the size and position of the window, which is what you should be using as "something" rather than the fixed constants that you are currently using.

In common English, your functions will calculate the upper left corner of the window, and add a number that's X% or Y% across or down the size of the window. This will get you the correct location on the screen regardless of where or how large the window is.

I can probably write the code for you in five minutes, but it's really rewarding if you can figure it out yourself. Here's a couple of clues:

  1. Look up the token %FrontWindowSize% which will return a string of two numbers which tells you the width and height of the front window.
  2. Look up the token %FrontWindowPosition% which will return a string of two numbers which tells you the X and Y values of the front window's position.

I'm not refusing to write the code for you, but I think you should try to write it yourself, if you want the flexibility that this method will give you.

I can also write a macro for you that will VERBALLY SPEAK ALOUD the percentages of the X,Y coordinates that the mouse is currently hovering over in the front window. But I think you should write that yourself, using the tools I just gave you. That's actually a pretty cool idea, and whoever writes it should post the answer in the Macros forum on this website. I'll do it if you don't want to. P.S. I just write this macro and it's really cool. It took only two actions! I'll just go ahead and post if for you on the Macros page right now...

1 Like

yes, I didn’t know you meant functions! That makes a lot more sense actually! I didn’t know that was possible, thanks for the heads up. I will try the implemention you just mentioned,
Though, in the meantime I looked at python, and made a very basic script with it. What this will allow me to do, is share the script event to window users. So I might be following that idea either too, or only.

But still, I think you’ve given me a very powerful tool to use in KM, as I‘m still a novice at using it. Tysm man!

Glad you are happy. (IHTYAH.) I just posted the macro in the macro page of this website which reads aloud the position of the mouse over the front window. If you look at that you can "cheat" and get some strong ideas for how to write the code that you need for this problem.

Actually, I used tokens, but I think KM has functions that lets you do the same thing. But I use the first feature that I think of, and there's often other ways to do the same thing.

1 Like

Please, how can I find the macro? It's name? Thank you!
Ops, found it, but it works only with KM 10, right?