Not sure if you got my earlier comment, but here it is and an additional question.
First, this is a masterful product. Kudos to you as a fellow long-term programmer.
Second, thanks for this — the editing problems I’ve had were just buggy AppleScript on my part, and the suggestion to run stuff through the AS editor to debug it solved my problems. I was expecting KM to do the same sort of error-reporting as the AS editor itself, and that was not a good idea.
Third, my big problem is finding a way to send an AppleScript result/output to the shell. I suspect it’s something simple and built-in, but my experimentation has so far yielded nothing.
My goal is to simply take the name of a file that Pages is editing and have that filename available to my shell script (also inside KM).
If there is other stuff that you need to do in the KM Macro, then returning the data (always a string) to a KM Variable is the way to go.
But if you just need to run a shell script with the results, then you can also make use of the AppleScript do shell script command.