Anyone know how to call a subroutine w/arguments via a URL trigger?

Or maybe using the command line tool? Thanks...

I have no idea, but you could make it work by creating a regular macro, and all that macro does is call the subroutine. You will have to split the arguments from the regular macro's single parameter. I presume you could come up with an unused character (maybe "~") that would be your separator between arguments. If KM doesn't have direct support for what you want, you may have to solve the problem this way. This is a fairly easy workaround.

Thanks @Airy. I'm hoping for a more general solution that wouldn't involve coding each new use case.

I suspected so, but nobody answered your response for hours, so I decided to submit my half-baked solution.

I would point out that even for subroutines, there is an option at the top of the macro called "Or By Script". If you choose from its options, there is an option for "or by URL" and "or by CLI tool." Both of these options specify how you can pass a parameter to the subroutine. Did you try this? Technically, it only specifies how to pass ONE parameter. But it would be interesting to see if that still works for subroutines. You should try it out.

I wouldn't be surprised at all if there was a way to pass multiple arguments to a subroutine. Peter often anticipates problems like this and provides solutions before anyone even knows the problem exists. So maybe you should try out the syntax and see, and try to guess how multiple parameters would be passed. My guess is that it would look like this for the CLI tool:

keyboardmaestro CC7139876-4579-41BB-7779-ABF957DC1F20 --parameter "P1" "P2"

That's definitely worth a try! There's a 10% chance it will work.

I had checked the docs for both and they seemed unlikely. Testing confirmed they only take one argument..destined to become the TriggerValue.

Well, it was worth a shot. Thanks again.

Macros can only be triggered with a single string argument. If you want more than one, you will have to encode the arguments somehow (possibly as simple as adding a comma between them, but it depends on their potential values).

Subroutines cannot be triggered directly (Subroutines are macros, so as macros, of course they can be triggered directly).

So you will need a macro, which you trigger with multiple arguments encoded as a single string, and which decodes that string into multiple arguments to pass to the Execute a Subroutine action.

Ah well. Thanks for the definitive answer @peternlewis. I can't say that I'm surprised but it was worth a check.

I'm sure there are many of us who spent the months after you first gave us subroutines by replacing our previous "sub-macros" with versions that would accept either passed arguments or parse the %TriggerValue%

I guess we'll keep doing that then. :wink: cheers!