Use a visible URL change OR lack of pixel changes within a certain period of time as a condition

Hi everyone,

I’m new here (and new to macros in general), so I’m hoping to pick your brain here! I’m pretty low-tech and don’t know how to use scripts, so this is my rudimentary way of doing things.

Short story - more context after the first 2 screenshots:

I’m trying to automate moving through the stories of Instagram accounts on a desktop browser.

  • I’ve already created a macro using the “down” arrow that works 99% of the time.
  • Moving to the next story normally causes a new image/video to appear on screen (and the URL also changes).
  • Sometimes, there is a glitch on Instagram, and the next story cannot be opened even when it is clicked (the preview shows up as black). When this happens to me, I just skip the story by clicking on the story after it (e.g. if Story A - delish works, but Story B - tastyuk does not, then I move on by just manually click on Story C - buzzfeedtasty).
  • I need Keyboard Maestro to know when typing the “down” key fails to move to the next story (either because the pixels do not change or the URL stays the same). The “pixels” being watched by Keyboard Maestro are the “left” and “right” arrows on either side of the story in focus, which temporarily change in size/position when moving between stories by different accounts.

I already created a macro for this that works (see below). However, when I embed this macro into a “parent” macro, it causes the parent (further below) to work incorrectly. I’m wondering if this might be averted if I used different triggers (e.g. the URL changed or pixels did NOT change after a certain period of time) - however, I can’t seem to find these conditions.

Skip Story.kmmacros (6.7 KB)

Context:

I use a now-unavailable browser extension to download Instagram stories manually. I’ve started using Keyboard Maestro to automate the process.

Download Stories - Responsive.kmmacros (12.0 KB)

  • In the browser, I open the story tray on Instagram manually to reveal all the available unread stories (e.g. delish, tastyuk, buzzfeedtasty, tastyjapan above). I then run Keyboard Maestro.

  • STEP 1 (no issues): Using the pixel color of the pause/play button on the upper right, Keyboard Maestro will determine whether a story is playing or paused. (I couldn’t figure out a way for “Find Image” to work, so pixels it is - when stories are playing, the Pause button is visible, and the gap between the 2 bars is not white. When stories are paused, the Play button is visible, and it is completely “filled in” with white). If stories are not already paused, Keyboard Maestro will pause a story so it doesn’t prematurely move to the next.

  • STEP 2 (no issues): Keyboard Maestro will click the purple button on the lower right to download the story (Again, I couldn’t figure out a way for “Find Image” to work, so I picked a very specific position on the screen). I then ask Keyboard Maestro to wait until all the stories have downloaded (“Download Successful” with a green checkmark appears on screen) before moving to the next account to download. I have set it to timeout after 30 seconds - and this is important because of Step 3.

  • STEP 3 (no issues): After numerous trial runs, I noticed that Keyboard Maestro sometimes fails to “click” properly if the browser just finished downloading a whole bunch of stories from the previous account (e.g. some recipes/cooking demonstrations are 50+ stories long). If the “click” fails, then no new stories are downloaded for the next account, and the green checkmark in “Download Successful” never appears within the 30 second timeout period… so Keyboard Maestro will reattempt the download. Otherwise, we move on.

  • STEP 4 (not always foolproof): We move to the next account in the story tray, and the cycle repeats itself until all the “accounts” have been watched and downloaded (ie. when the background of the webpage changes from black to white). However, if Instagram has a glitch and the next account is not “clickable”, then the story tray does not move to the next, and the macro keeps downloading the same account over and over and over again.

When I insert the “Skip Story” macro after the “Down Arrow Keystroke” action in Step 4 (either as “Execute this Macro” or just inserting 2 individual actions), the parent macro starts to malfunction - accounts start getting skipped incorrectly even if they are actually available to watch. I want the macro to always attempt to see (and download) the next possible account - and only skip it if it cannot be opened.

Hopefully I explained myself correctly? Please let me know if this is unclear, and thank you in advance for your help.

Before going any further...

Your title includes "a visible URL change", but there's nothing obvious in your macro that checks the URL. KM has some Tokens for that, including "%ChromeURL%", so you could:

...setting the "Pause Until" Action's timeout behaviour to suit what you want.

And see if the pause/play button is actually a detectable button. Add a "Press a Button" Action to your macro and, with that page frontmost in Chrome, click the Action's "Button" pop-up and "Scan Front Window of: Google Chrome". Click the pop-up again and, at the top of the menu, you'll know have "Google Chrome" and a sub-menu of all the detectable buttons.

It'll also be easier and more robust to use a "Button Condition" in your "If" and "Pause" Actions.

Hey, @Nige_S!

Thank you so much for your tips! You provided me exactly what I was looking for.

I was able to incorporate “Press a Button” Action for the pause/play (to replace the pixel checking action in my Step 1) and added an action that compares/looks for a change in URL. I would have never figured this out on my own! I’m gonna try to learn more about tokens, since this is so new to me.

Thank you so much again!

Start with the Manual. No need to learn it, but even a quick skim will bring you up to speed on the Keyboard Maestro fundamentals, the terms used in the application and on the Forum, and will give you an idea where to look when you have a question.

Similarly, have a look at what's available on the Actions, Tokens, Functions, and Triggers Wiki pages. There's a lot, and even more functionality hidden behind options and arguments, so bookmark them ready for this "I wonder if KM can...?" moments.

Never ever be afraid to ask on the Forum. We all started where you are now, everyone here remembers that and is willing to pay it back if they can -- and you'll never ask a sillier question than some of the ones I've posted :wink:

And, as you browse the Forum, don't get freaked out by the number of macros that head off into AppleScript/shell/JavaScript/Swift territory (some people see those and start thinking they have to learn all those too). 99% of KM macros don't need that kind of complexity, but they're over-represented here because people often ask for help when they are trying to do something that KM can't do (cleanly and robustly) with its "native" Actions.

There's a lot to learn -- but you only have to learn as much as you need to get what you want out of KM. Have fun!

1 Like