MoveMouseToWord Macro (v1.0)

YOU have saved me HOURS..... :slight_smile: Thank you and have a safe trip

1 Like

Thank you for creating this macro. I have used FindImage for years, but the last year or so it seems that what worked one month doesn't work the next. I'm guessing that is because I'm not running the macro at the same time of day each month. (I use it download online bills and bank/investment statements).

I am using a very old Late 2014 27" Retina Mac with an Intel i7, 32 gigs of RAM and 1 TB SSD. To find it the first time takes about 20 seconds. Once it has been found it is virtually instantaneous if i run it again.

I also found that the mouse wasn't moving to the location the first time I found it. I had to add this

right under:

to get it to move.

I saw there were several comments about designating a certain portion for the search, and you replied it might make it only marginally faster. For me, since I'm only searching a Safari window, by limiting it to that I wouldn't have to worry if the same word was elsewhere on the screen. (As you mentioned above, one of the reasons a person may have been having trouble is that the triggering macro, with the search word, was visible on screen). Something similar happened to me in that I was searching for "Summary" and just by coincidence a message popped up giving me a "Summary" of my screen time. And as that pop-up was higher up on the screen than my Safari window, it found that pop-up and stopped. So I too would like to see if we could tell it to just OCR a particular window like the active Safari window.

I also had an idea about finding something other than the 1st instance of a word. I was think that you could add a 3rd parameter where we could designate which one we wanted. Then as you searched you would iterate a counter until the number found equaled the number we wanted. Besides a pure number, I don't know if it would be possible to do a Top/Bottom/Left/Right most, first/last, etc. like KM can do with found images.

You make some good comments. I'm very glad you were able to understand the macro and modify it to suit your needs. Yes, you could modify it to start searching only a specific application's window. But even if that narrows your search area by 50%, that's only one step in a ~20 step binary search, which means a 5% increase in speed (roughly.) This is why I didn't add a starting area to my algorithm, as it doesn't increase the overall speed by very much.

Yes, I think it would be possible to modify the macro to search for the leftmost or topmost occurrence. In my case, I wrote this macro to find and click on a phrase like "Click to Continue" and in my situation the word "Continue" appears only once on the screen, so I didn't need that feature. Moreover, the words "Click to Continue" were in a 200 point cartoon font, so my macro was really fast. (And Apple's Text Recognition works very well with cartoon fonts.)

P.S. Binary searches don't take into account the fact that bisecting an area could accidentally bisect the actual word that you are trying to find, resulting in a failed search, so I had to make some modifications to account for that potential problem. It was tricky, and it will get double tricky if you want to search for "leftmost" or "topmost." I'm not sure if I'm mentally ready to take on that task.

Thanks for the reply. My interest in specifying a Safari (or Chrome, etc) window isn't for speed but to be sure I'm finding the word in the correct place, just in case it is somewhere else on screen. While this may be pretty rare in general use, (although it did happen to me), as you pointed out if I had the macro on screen while I'm working on it, that might be found. So, there are definitely use cases for it.

Fair enough. If you want to modify the macro to start searching over a specific area, like the area taken up by the Safari window, I think all you have to do is modify the coordinates in this action:

image

You can either insert fixed values, if you know where Safari will be located, or you can extract the actual values of the Safari window's location by placing Safari on the front of the screen and then extracting the coordinates using a token like %FrontWindowFrame% or any of a variety of similar tokens.

@Airy I didn't find that going via BTT is any quicker than using your subroutine.
While your subroutine is finding the word well, I placed a pause after calling the subroutine and Move and Click Current Mouse Location and the click part is not working - is there a better way to do it?

Wow. Perhaps that means BTT is implementing my solution. I wasn't expecting that.

I can't help debug your macro if I can't see your macro. The click action is inside your macro, not mine. I can't imagine why your click action isn't working, but if you show it to me, maybe I can help.

Sure - here you go. The first step is used just to populate the variable for testing. In the future it will come from another macro.

Find Word on the Screen and Click .kmmacros (3.0 KB)

The first thing I see is that you aren't checking the return value to see if there's an error. Although this may not have any bearing on the issue, I think you should check the result. After all, you say it's not working, so why not check the error return value?

The second thing I see is that the macro works fine for me. I copied your code and I had no problem. Therefore perhaps the problem is something outside of the macro, like the name of the app you are using. What app are you using which contains the text you are trying to locate? You probably also have to tell me what trigger you are using for this macro. Currently your macro has no trigger. Therefore I suspect you have the KM Editor as the front application when you manually trigger this macro. Is the target text inside the KM Editor window? I'm just guessing these things because you haven't given me enough detail. Since your macro works fine for me, you have to give me enough detail for me to replicate your problem.

I will incorporate the return value as you’ve suggested.

I was testing the macro with a random trigger - I think it was ctrl-option-cmd-B and also by clicking on play button in KM.

I was attempting to click on ‘compose’ button in Gmail opened on another half of the screen in Safari and then ‘topics’ on KM discourse also in Safari. The mouse was correctly positioned after you macro subroutine ran, but I didn’t see a mouse click opening a new email to compose. I didn’t test it beyond these two options.

While running the macro, I moved KM maestro window away so that the trigger word would not be one to be found.

I think I know what the problem is. You just "moved the window away", but if that's all you did, then you didn't actually make Safari the front window. As a result, when your click action runs, it actually does click, but all that happens is that the Safari window is placed in front. That's how macOS works:... if your Safari window is not at the front, all a click will do is bring the window to the front. So your click action is working, it's just not doing what you want because your Safari window wasn't at the front.

That's my theory based on what you said. There's always a chance that I'm wrong, but I have to go by what I see based on your description.

Yep - you are correct - it works if I change it to two mouse clicks one after another or a mouse double click.

Appreciate your help.

You are welcome. You may find it safer to use an Activate Application action instead of using the two click trick.

I now have a MacBook Air 15″ M4 and now the macro works.

It moves the mouse pointer to words like "Arano", "Resources" and "New": very nice!

However, when I set the word to identify to a symbol like the triple horizontal bar "≡", this doesn't work. Would it be possible to modify the macro to accept single characters/symbols too?

FIRST PROBLEM: My macro simple calls Apple's OCR engine. If Apple's OCR doesn't "read" a triple bar, then my macro can't search for that either.

SECOND PROBLEM: Your triple bar character is a single character standing alone. Apple's OCR cannot read a single character standing alone, even a letter like "A".

First suggestion: use Find Image instead. But finding a small triple bar character may sometimes not work well because the Find Image action may find some false positives.

Second suggestion: use the Press a Button action. You may find that it works perfectly for this app. You will have to read the Press a Button action's documentation to learn how to use it. I don't have your app so I can't test if it will work for you.