Can I make a macro succeed or fail?

Is there some way I can make a KM macro "fail" so that the calling macro can check the ActionResult token to get some feedback from the macro? This would be like returning a boolean value from a function. There's a Cancel option in this action:

It seems to me that it should be easy to add an option from the list in that action to say "Cancel This Macro with Failure". Or is there a way to do that already?

Actually, just before posting this, I found a sneaky way to achieve this, but I still want to know the "right" way to achieve this. My sneaky way is to have the last action of my macro (that I want to send back a fail signal) perform an action that fails. The first thing that came to my mind was an Execute Shell Script action with a badly formed command in it. But this is a kludge -- can it be done smarter?

What about the new Assert action? Could that be used to set a variable or run another action that the calling macro could read to know that the called macro and failed?

You suggest that a Condition clause in an Assert action could modify a variable or call another action. If there’s a way to do either of those things, please tell me. I would love that functionality.

It seems that I mistakenly remembered the Assert action as one that could contain other actions, like an If/Then or Switch/Case; clearly this is not the case, so my apologies if my errant suggestion led you astray. That said, I’m still not sure why this couldn’t be possible with a negative If/Then action (i.e. if none of the below conditions are met). Obviously I don’t know your whole workflow here, so I can’t offer any detailed suggestions, but could you not add, say, a Set Variable action before the Cancel This Macro action that sets a variable to a value that the calling macro could read and change its behavior depending on that variable’s value? As always, the more details you can share about your workflow and goals, preferably along with the macro(s) themselves, the more help the community can theoretically offer.

No need to apologize. I appreciate that you try to help. I realize I don't always explain my macros. Partly that's because I write long macros. I doubt that anyone but Peter has written more macros than me, and I'm not even sure about Peter. Your idea with using variables could work. For example, I use a lot of Execute Shell Script action. After each of those actions I need to add an IF statement to modify a variable to indicate an error, like this:

That would be a lot of code. But now that I think about it I guess I really don't know what I want. So let me change my request. I would like the Execute Macro action to have a flag that prevents a failed macro from aborting the current macro. Like this:

Currently if a macro fails all its calling macros also stop running. Is it fair to ask for this enhancement?

1 Like