Hotkey when webpage ui changes

Great, here's a screenshot of something I am working on.

Let me see if I can get this done. Thanks!

Based on my experience and the font sizes I see, I think my macro will work.

But if it generates too many false positives, based on a handful of characters being read differently each time, it should be easy to introduce a threshold to make sure that the next page is "substantially different."

Would I be correct in assuming that on each "changed page" there would be at least ten words that were changed? Would that be an accurate statement?

OK! I think this is sort of working! I mean it seems to be working on my test page here (I can't seem to login right now to what I am looking at doing). So if I understand correctly, if I want to take a screenshot (or trigger a hot key) I can set it in the first half of this script.

Can you guide me to how this works? And if there's a tutorial beyond youtube? Is this something worth paying for? Thanks for your help!

https://learn.macsparky.com/p/km

Yes, you understand. You can add your screen snapshot there.

But I've got better news... I've managed to make my algorithm much more reliable. I think I'll upload it soon.

Great, I am glad I am understanding it now: ) Oh yeah? Please keep me posted. TYVM

I just posted a more reliable macro here:

It's public domain! You don't need to pay!

There are no tutorials for this. It's a very short macro. Read it and then ask me your questions.

Basically, I'm using OCR to read all the words on the window, and letting the user take an action if the number of "unique words" differs by a certain amount.

This is great - I almost feel I installed Keyboard M and immediately went into the trenches with a need and you came on top. I'll get this installed and see how it goes tomorrow! Talk soon thanks!

I'm glad to hear that. If it doesn't work perfectly for you, let me know, and I'll see if I can improve it. But I'm pleased with it already.

Hm, I can't seem to get this one to work at all. I wonder if there's something funny about how it gets imported. I added an alert at the very bottom of the script you had there it continues to pop up every 5 seconds for me, whether or not I scroll the window down or leave t.

Hey,

I think we are almost there - it seems though the absolute value is a number which makes sense I get the calculation.
image
But then I don't see where we are taking the value of Saved Text and converting it to a number to do math on it. Therefore it always evaluates to false?
Thanks

Aha! Good debugging. This could be because you were running my first macro, which did NOT save a number into SavedText (it saved a string), and then you loaded my macro which DOES treat SavedText as a number. If you delete SavedText, it should start working. I think. You can delete the variable a few different ways, such as opening the KM Settings / Variables window.

In the future I will be more careful not to assume the contents of global variables when I upload macros.

Hey , really appreciate the help so far.

I've tried to do as you suggested but I am still running into a bit of a thing. Variable screentext populates with a number accurately.
However, if I scroll on the page now it gets modified whcih is great. The values inspector seems to flash values for SavedText like briefly and then gets zerod out.
So if now I put an alert box at the bottom in Otherwise, I get a contant popup.

So if I leave it there under the if true box and I don't do anything with the page I don't get a popup. But if I move the alert box to otherwise then I get the popup.

I'm wondering if the value of the variable SavedText is still set or something. So I made an action to set Saved Text to blank and the loop continues.

Yes, well your attempt to fix it won't fix it because setting the saved text value to empty will mean that there will always be a difference between "empty" and the current number of unique words on the application.

I thought I was an adept user of KM but I don't think I have ever seen the "Value Inspector" before. I feel dumb now. Thanks for showing me.

Let me read your post carefully and try to figure out what's happening.

I think I fixed it by adding this to the top of the macro:

image

I'm still trying to understand why this makes a difference. I had thought that conditions with empty variables would have turned out to be false. I don't understand fully yet. Give this a try.

Thanks! I'll give it a whirl here in a few hours!

If the change fixes your issue, I should update the macro.

I have tested this script with the first action and this solves the issue from what I can see.

Thank you very much!

You are welcome. Thanks for confirming it worked. I will update the macro on the other page.

My macro does use a lot of CPU power, but my philosophy is that if nothing else works, don't be afraid to use CPU power. It's your computer and you can use the CPU as much as you want.

Maybe someday there will be another solution that doesn't use as much CPU.

In your situation, you might want to change the trigger time from its default of 5 seconds, or you might want to put the macro in an infinite loop instead of a timer. Do whatever suits you.

Yeah this is perfect and I learned something. I am not sure exactly where to start learning something else but this was definitely a great back and forth to learn something. Thank you for the guidance and taking that time to help me.

I think I will adjust the timer if I am going through the material myself studying - right now it works great for capturing the window and then PDF'ing the whole thing. That was my objective, the material is not published via PDF and I have use cases where a PDF is good to have.

I'm on a newer PC with a hackintosh build so my resources I feel are not as limited - the hardware with Apple seems a little low. I'm sure I'll have other questions down the road.

Cheers!