On Step Failure Jump to Step

In the Control Flow folder there is an ‘If Then Else’ Try playing with that.

. . . Stephen

Wonderful thank you I will give it a try!

Thanks I made some progress, I thought it might be best to give it a try again in after a few days since I couldn't get it working.

I am no doubt doing something wrong, I am sure there is a better way then what I am doing. It feels like I shouldn't have to keep adding the same string of actions multiple times just to have it move on if something fails. This leads to a lot of clutter and extra work just to fix something for macros that then proceed to do a lot of other things if anything changes down the line, I can't simply just change one delay and test it, I have to change both delays since everything has to be duplicated. Like I said I am sure I am not thinking of this properly since I am so use to the way I have been doing it in QuicKeys for years.

The other thing that is not working even with this set up is if there is more than one of that image on the screen which there often is it sill won't move on to complete the of the commands or in this case the single command.

It seems like a bug that "Any of the Following Are True" doesn't work if there is more than one of the same image on the screen but "not all the following are true" works only if there are more than one of the same image on the screen. I feel like I am making this way more complicated then I am sure it needs to be.

Perhaps I gave too much detail or this just can not be done very easily. Any examples or other posts of how to have Keyboard Maestro just skip a step that failed if you so choose. This seems to be complicated in Keyboard Maestro depending the scenario.

Hey skillet,

What version of KM are you using?

You haven’t told us what app you’re working in or what you’re doing.

The pieces of your macro don’t really offer enough information to evaluate what you’re doing OR to test with, and unless a question is very straightforward it is often very difficult to answer without testing.

There’s a tricky way of dealing with multiple images on-screen which may or may not be of use to you: Click each button on-screen

I’ve got a question in to Peter about how the Find-Image action might be improved, and we’ll see if he likes the idea (and can do it).

So stay tuned.


Best Regards,
Chris

Thanks for the reply CCSTONE, I never know if I am giving too much info or too little sometimes. I am using Keyboard Maestro 6.4.8 which should be the current version according to the check for updates.

I am running this macro with Cubase 8 but really if there were some other examples of just skipping a portion of the macro that would be great. I am guessing from the way things look that is not really possible without nesting things in another command.

Thanks of the click multiple images thing, that is very helpful and will be used no doubt. For the sync button it can often show on multiple screens but they all are related to each other in Cubase, you press one and they all turn on. So for me I didn’t really care which of all the buttons Keyboard Maestro press just as long as it pressed one of them instead it pressed none of them. However sometimes there is only one on the screen so that presented a problem too.

There is not “goto” in Keyboard Maestro actions. No way to “skip N actions” or whatever.

If you want to skip N actions, you use an If Then Else action.

If you want to detect whether an action failed, you use the TriggerResult ActionResult text token.

You can find an image on the screen, and if there is more than one of them, you can find one at random. You cannot (yet) iterate over matching images on the screen (well, you can’t, I can : -).

Hey skillet,

Too much info in help situations is nearly always better than too little.

Well organized is even better.

Always remember that your audience may never have seen your problem and try to give them enough information to understand the process.

Think of it this way:

I never want to see just the rate/time problem all written out.

I want to see the vehicle and the course - because very often I immediately see there's an unused nitrous tank on the vehicle and a giant shortcut in the course.

The written problem usually misses all of those things.

The author usually leaves things out, because (s)he already knows the problem pretty well and makes incorrect assumptions about what someone else needs to know to help.

I know this well, because I've been helped and given help on the Net for over 20 years.

Just knowing you're working in Cubase 8 lets me look at it on the Web to get an idea of what you're dealing with, and that changes my perception of the problem considerably.

Back to your problem.

You can always set a variable like completionFlagVar to false and then set it to true if your conditional evaluates true.

Set completionFlagVar to FALSE
If All Conditions Met Execute Actions:
  Your conditional
    If TRUE then:
      x
      y
      z
      Set completionFlagVar to TRUE
    Otherwise Execute the Following Actions
      Set completionFlagVar to FALSE

If All Conditions Met Execute Actions:
  If completionFlagVar is FALSE
      Do something…

You can group your conditionals in many ways for quite a lot of flexibility.

I'm not certain what the TriggerResult text token does and have a question in to Peter about it. I think maybe he mistyped, but we'll see.

Peter has indicated significant improvement for 'Found Images' in KM7, but unfortunately we'll have to wait some time to see them.

Okay. Hopefully my rambling has added some meat to the pot.

-ccs

Sorry for the delay in responding and thanking you both. We had a baby last Friday and my attempt to work through these replies was not too successful yesterday.

So if I am understanding this correctly from what I could find in documentation and the forum is if I use "Success Result of Last Action" which puts in a token of %ActionResult% and would have to be used with "If Then Else" nested for every single action so you can "Display text in a window" if the action fails. Is that correct Peter, if so it seems very laborious. Perhaps this is one of those things you were referring to when you said "Keyboard Maestro strives to be very orthogonal in its features" Transition From QuicKeys [Keyboard Maestro Wiki]

There is still so much for me to learn in Keyboard Maestro I can't really cast any judgment and just want to learn what is and what isn't. I feel like in a lot of ways I am taking baby steps again.

I couldn't even find that in the options, not sure why Peter put strike through font on that, maybe it is a legacy token?

I'll continue to try to make heads or tails of this (unfortunately not that advanced yet but would love to be), I have googled but can't find anything for "completionFlagVar" I assume this is a generic term for what would have to do with whatever ActionResult text token returned.

I'll keep plugging away at learning and accomplishing these tasks. It defiantly feels more complicated in some ways but I am sure in the long run more flexible.

Thanks all for the help, very appreciated.

I was right - it's ActionResult.

That's simply a variable name - hence the 'Var' at the end. :smile:

It is.

In some ways yes - in some ways no.

QuicKeys and Keyboard Maestro are two very different paradigms for doing similar tasks, and each has its strengths and weaknesses.

The thing is that QuicKeys is now a dead product (without an update since Dec 2009), and Keyboard Maestro is in active, vigorous development.

-ccs

In principle, yes. In principle, you could follow every action with:

If text %ActionResult% is not OK
    Notify %ActionResult%
    Cancel This Macro

However, most actions simply cannot fail. Pause, Click (except at found image), Type, etc have no failure cases.

Those that can easily fail (eg Select Menu / Press Button) have a setting to abort the macro if the action fails.

And scripts which can fail can handle their failure themselves if desired.

I actually just checked and I don't use the ActionResult text token in any of my macros. They are generally written to work regardless of the state. Some of them check for specific states and report issues if the state is not as expected, but frequently this is not state that would be detected by an action failure, its state that indicates something is not setup as expected and executing the macro would likely go off the rails.

So I suspect if you're frequently writing macros that are wanting to know if the action has failed, you're perhaps not going about it in a natural (for Keyboard Maestro) way. Or maybe your problem set is just significantly different to what I am used to (in which case maybe Keyboard Maestro will not be as nice a fit for you and then you can let me know where it is being cumbersome and I can potentially adjust it as necessary going forward).

More than anything it is not that I need to know if it failed but to not stop running the rest of the commands. Although there are some macros that if they fail then I want them to skip on to another step or nested action like a repeat one loop example you gave here [quote="peternlewis, post:4, topic:360, full:true"]
The current best solution for a Group action is to use a Repeat 1 Time action as a stand in.

A Group action, and being able to color/label actions is on the todo list (its a surprisingly long list though!).
[/quote]

. It looks like nested groups is coming in KM 7 so you might be able to have the macro jump to other locations depending on success or not.

Makes sense and a lot of times I just use keystrokes so that wouldn't be known if it fails or not either so I use delays to help with consistency of OS or hardware lag on slower systems.

Only because I am so thick, it might save a lot of verbiage, if possibly an example uploaded macro where if a picture doesn't exist then it will use Example Finder Macro.kmmacros (922.2 KB)

If text %ActionResult% is not OK
Notify %ActionResult%
Cancel This Macro

If the action fails assign the macro to continue on to the rest of the actions in the macro which are key commands.
I don't understand how you attach that to the image action or menu action itself.

Thanks for all the clarification cots, when you are a noob sometimes you don't know what is up and what is down.

I may not have been clear on what I’m saying.

You can detect if an action fails (presuming that it can actually fail) by testing the %ActionResult% text immediately after that action (it will be OK for success, and something else otherwise).

But generally you want to instead test the state of the Mac and choose what to do based on that to ensure your macro does not fail. So instead of

Press Button "Whatever"
If text "%ActionResult%" is not "OK" then
   do whatever
else
    do whatever else

instead do something like:

If button "Whatever" is enabled
    Press Button "Whatever"
Else
    Notify "Button is not enabled"
    Cancel This Macro

Or whatever you want. In other words, ensure your macro can handle the state of the Mac and behave as you desire. The Else clause might do something to make sure the button is enabled for example, perhaps bring an app to the front, open a window, whatever else. Or it might just complain and stop.

Is there any macros on this forum that, that you can think of that show good use of the %ActionResult% after an action (even if it may not be the best approach in every case). I tried the later example with images and it didn't seem to work as consistently as I had hopped for some reason. It worked about 70% of the time when the state wasn't what it should be in order to perform the other actions.

Thanks Peter for all the help.

I don’t have any macros that use it myself, and on the forum, the only useful mention of it is Using ActionResult difficulties which shows an example where you would use it - immediately after a Select Menu Item action.

Even then, better would be to use If the menu item “Whatever” is enabled, then perform the task (unless it is a poorly behaved application that does not update its menus in response to accessibility requests).

I assume you are talking about the menu items changing state to say something different if it is enabled like "Open Mixer" if it is closed and then change to "Close Mixer" if it is open. If that is what you are referring to unfortunately in my case with Cubase it doesn't change the name at all and always stays the same name regardless if it is opened or closed. What is worse is if it is behind a window and you press the key command it goes away when you think your are pulling it open so you wait then realize it must have closed so you press the key command again. I want it to always pull it forward regardless.

Thanks for the link to that other post that has solved my problem though it took some doing to figure out.

Hey Skillet,

Peter is not really speaking to your specific problem with Cubase.

You have a biased impression of branching based on your experience with QuicKeys.

In QuicKeys it went:

Do this action
    If action SUCCEEDED
        Do this…
    If action FAILED
        Do this…

Keyboard Maestro generally attempts to follow more canonical programming principles in graphical form.

IF THIS <CONDITION>
    THEN THIS <ACTION>

ELSE IF THIS <CONDITION>
    THEN THIS <ACTION>

END IF

There are times and places where either way of thinking might be the best solution to a problem, BUT wrapping your head around the way KM works is necessary - because otherwise you’ll keep banging your head against the wall - “Why doesn’t it work the way QuicKeys does…?” (BTDT)

Because it’s Keyboard Maestro, and Peter is Peter. That’s why. :smile:

-Chris

Right, I was just trying to understand a little more what he meant by giving a specific situation. I am completely fine with conforming my thinking, I just have been struggling like mad to find examples of how I find out if conditions existed or not so I could have it make the proper choices.

Thanks for all your great posts and help, sincerely appreciated!

Thanks Peter for adding the "Failure Aborts Macro" and "Notify On Failure" to Keyboard Maestro 7.

1 Like

Woohoo! Celebrate small wins! After reading this I just used my first "If Then Else" action where the actions stopped when the button wasn't present.

It's great to learn something! :muscle:

1 Like