TriggerValue: how to process it to extract the query parameter value?

Reference: Open URL Passed from KM Public Web Server
Docs: token:TriggerValue [Keyboard Maestro Wiki]

The %TriggerValue% token returns the value associated with how the macro was triggered.

I have looked for a good 30 mins, and haven't gotten very far. The term "value" in the documentation is overloaded.
When I ran @JMichaelTX example the output value is literally "triggerValue=hi"

Question: How do I extract the value of "hi" in the above query fragment? That is, the query parameter value. Is there something built into KBM that extracts this or do I have to manually process the string?

You can easily access the individual parts using the token array notation:

%TriggerValue[0]% // expect to see string "TriggerValue"
%TriggerValue[1]% // expect to see string "hi"

output:

1
TriggerValue=hi

OK, you are using the Remote trigger, so the TriggerValue token will contain the text of the URL after the ?.

So in the case you should the text after the ? is:

TriggerValue=hi

%TriggerValue[0]% returns the number of comma separated entries in the array. Since there are no commas, it returns 1.

%TriggerValue[1]% returns the first comma separated entriy in the array. Since there are no commas, it returns the full text, it TriggerValue=hi.

What are you actually trying to do?

Hi Peter
It seems that the example generated by kbm ?TriggerValue= is misleading. I was thinking that is would creating a mapped value where TriggerValue would equal everything to the right of =
( Edited: this is not the case - checked with a new macro )

So the url string after the "?" is the TriggerValue.

I'm trying to pass a query parameter value to shell script as an argument. That part is straight forward.

So in my case I will need to remove TriggerValue and rely on the order of values, an array as you've stated, not a map like query params normally work.

This resolves my issue.

I don't believe there is an example with ?TriggerValue= - there certainly should not be as that would be misleading.

The example is ?TriggerValue where TriggerValue is what ends up being placed in the TriggerValue token.

Correct.

Yes, Keyboard Maestro does not have any URL parameter processing facilities (and URL parameter format is mostly just a convention anyway). You can process them yourself if you desire, but if you control both ends I'd definitely simplify it to just an ordered list of parameters as you note it would be much easier to process.

1 Like