Way to Resize an iOS App Running on macOS

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:

https://youtu.be/dwNMrMVyoPo

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)

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:
image

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?

If you are talking about the macro I made to speak aloud the position of the mouse, the answer is here:

If you are speaking about something else, you have to explain what you are referring to. This was a long post and I can't tell which macro you are asking about.

1 Like

Just this macro, thank you!

Great. Thanks. I'm not sure which version of KM this macro requires. I don't think it requires KM v10.

1 Like

Yes, I tried it just now in KM 9.2 and it works!

Great news. If you need changes/updates to the macro, I'm happy to consider it. I think this macro will help me write code to do things like pressing buttons in apps. To be honest, I think this "percent click" is so useful that it should be considered as part of a new feature for the Mouse Click action in KM.

1 Like

thank you for your support!