Hotkey when webpage ui changes


I am trying out KM and had a problem I would like to solve. I'm currently trying to activate a hot key to take a window screen shot with an app. This all works but my trigger is the big question.

I've tried window focus mode but the options do not work for me as the URL and title of the webpage do not change as I navigate throughout the module.

However, the UI elements change. Some suggestions have been to use tamper monkey with a custom javascript function to monitor etc and then KM to activate the actions.

Any help would be appreciated :slight_smile:

I'm perplexed. If you wanted to use a hotkey to take a screenshot, then it will always succeed when the user presses it. Maybe what you meant is that you want a KM macro to figure out when the contents of the page change, and have KM on its own accord take a new screenshot whenever the page changes. If that's what you want, then a hotkey has nothing to do with it.

Right. I guess I started out with a hot key but then wanted to further reduce the friction and have the screenshot taken automatically after the web page contents change. Is this possible?

Sure it's possible! The reliability may not be 100% accurate, so you might end up not liking it. I can probably write a macro with a couple of actions that will do it, but my food is beeping on the stove right now. I will enjoy this challenge.

Great, that would be great if I could see even how that might possibly work. I am into tampermonkey trying to send commands to KM...... alas. TYVM

Okay, here's a screenshot of a very simple macro that monitors the front window and, every 5 seconds, says "Changed" if it believes that the window has changed. You can reduce the time to 2 or 3 seconds if your Mac is fast enough, or you can put this into an infinite loop.

I've tested it on several windows and it works well for some but not for others. Since you haven't shown the window that you are testing, it's impossible for me to know whether it will work for you or not.

Even if it doesn't work very well, there are minor tweaks we can do to improve its reliability if you find it isn't working well. (eg, change the font size of the text in the window.) There are even some more advanced modifications I can make to this macro if it is needed.

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!

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.


I think we are almost there - it seems though the absolute value is a number which makes sense I get the calculation.
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?

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.