I'm glad it works!
I think mistakenly pasted the Swift snippet with the shebang line. I don't think it should make much difference if running from Execute Swift or Execute a Shell.
ADDENDUM: Unless, of course, the script is compiled, in which case the Execute a Shell should be faster.
The macro doesn't have the shebang and runs in Execute Swift.
I can hardly take any credit for this as I mainly got AI to generate the code and AI most likely scavenged it from web snippets that scavenged it from:
which, I now see, received an honorable mention--later rebestowed on XCode's version-- on KM's forum:
(FWIW, I still use it and never use the one bundled in XCode)
In other words, it's a long ways from original.
(Besides, in my neck of the woods, that designation is not necessarily a good thing.
)