I have a series of backup macros to export my KM Scripts, Shortcuts and StreamDeck profile. I then commit the lot to git. What is the best way to chain these together?
Do I write a 5th macro and then call of the others inside it? In that case is there an elegant way to share any results from each, but continue if there is failure?
One way you can do this is by giving your 4 backup Macros an "Executed as a subroutine" Trigger each. And check the box, "Returning a value".
Then call these 4 Subroutine Macros one at a time (as you have said) using a 5th Macro.
One advantage of Subroutines is they make it easier to send and receive values. Which leads to:
Here's one way. You can set any Actions that possibly might fail in the Subroutine Macros to not abort the Macro on Failure.
And after each of these Actions, put a Set Variable
Action that saves their success or failure to a Variable, making use of the Token %ActionResult%
And at the end of each Subroutine you put a Return from Subroutine
Action that returns all of these results, with each result separated by a comma.
Your Calling Macro (the Macro 5 you mentioned) can then make use of those results to display a message or save the message to a log file, whatever.
It's easier to show by example. Here a Calling Macro is calling 2 Subroutines and then displaying the results of the Actions in those Subroutines. For the example, I made the Actions simply open Finder Folders. If the Folders exist there will be success and if the Folders don't exist there will be failure.
Both of these results get reported back to the Calling Macro. In the example run below, I made a Folder on the Desktop called "Test Folder". None of the other folders existed so, the Actions to open them fail and report back. (It is very important that the Actions are not set to Abort the Macro on Failure.)
Here is one of the Subroutine Macros:
And here is the calling Macro:
Here is the calling Macro running. (As only one Folder actually exists, it gets opened and the report says what happened).
And here is the actual Macro Group:
EXAMPLE Run Subroutines with Report Macros.kmmacros (11.8 KB)
Of course you can send any information you want back to the calling Macro using the Return from Subroutine
Acton at the end of each Subroutine.
Also it's probably worth setting any and all Actions in both the Calling and Subroutine Macros to "not Abort on Failure" otherwise any failed Action could bring everything to a halt.
Wow. Its funny I thought this would like five minutes. I'm a 1/3 of the way through after 10 minutes. Thanks to @Zabobon to opening my eyes as to all the details involved here.
Thanks @peternlewis for creating a tool that makes all of this possible.