How to Pause Until ... But if That Fails Do Something Else?

I have a macro that requires use of Found Image conditions and it relies on pages to load and then, when certain UI elements are visible, it moves on to the next step.

Problem is sometimes there are issues with loading and the components fail to load. However, usually this is corrected by simply hitting reload. So, I'm trying to work out the best way to do this. Essentially I need this:

1 Load the page
2 Pause until appears
3 If does not show up within 10 seconds
4 Send keystroke CMD+R
5 Go back to step 2 and wait again

Can someone tell me how I can do this? Thanks :slight_smile:

2 - Use pause until page is loaded action

Put 5 additional second pause just to be safe

3 - Use “if then” action to have it find the image and cancel just this macro or else if failed Command-R

I agree that this is good in principle. However, you should always try to use the “Select or Show a Menu Item” action instead of a hotkey action (like Cmd-R). This is because the menu item action waits for the associated tasks to be started by macOS/the application (sometimes even completed) before allowing Keyboard Maestro to continue with the next action. A keystroke action moves onwards immediately which sometimes leads to hard to diagnose issues in macro flow.

1 Like

Hi @Lloydi. If you insert your "image to find" in this macro, I think it will achieve your objective. Please note:

  • I've embedded a few comments, but if anything isn't clear, feel free to ask.

  • I've assumed you are using Safari.

  • This macro opens this forum page and searches for your Profile Picture (green L). Obviously you'll want to adjust that portion of the macro.

  • The inner Until action waits only 0.25 seconds before checking for the image. This approach has the advantage of accommodating pages that load slowly, but also does not add an unnecessary delay for pages that load quickly.

  • The macro will wait 10 seconds (0.25*40) before the first Reload. The time can be adjusted by changing 40 in the Until condition. See that embedded comments for more information.

  • The outer Until action is used to repeat the Reload (adjustable, but currently set to 3). If you only want to do one Reload, you could remove this outer Until.


Safari—Load Page, Wait for Found Image, Reload If Necessary Macro

DOWNLOAD Macro File:
Safari—Load Page- Wait for Found Image- Reload If Necessary.kmmacros (44 KB)
Note: This macro was uploaded in a DISABLED state. It must be ENABLED before it can be run. If it does not trigger, the macro group might also need to be ENABLED.

Macro-image

I could try that but it's a little more complex in that it's not a straightforward page load - the content is inside an extension running in Chrome and it's not really a full page reload; parts of the page are updated on the fly rather than, say, a new URL loading.

That's a good tip. I will bear this in mind for future :slight_smile:

Thanks for this - I will take a look and see if I can adapt it to my needs (specifically, it will be in Chrome, not Safari, as the content this all relates to is running in an extension).