Passing parameters from Trigger Macro By Name

Is there a good way to pass parameters to macros from the Trigger Macro By Name search box. For example, I’ve created a macro to start a countdown timer. If I type ‘timer 30’, then no results are found. So I can’t pass the duration to the macro.

To get around this I created a Comment action and added a bunch of numbers I want to use as duration to it. So now searching for ‘timer 30’ gives me the timer as the result and it will trigger the macro with the string as the parameter. Then I extract the number from TriggerValue using a regular expression. The method works for this example but obviously I can’t use it if the parameter space is too large. Such as a file name. I was thinking of using it sort of like Alfred.

Is there a better way or is this simply not possible with Keyboard Maestro?

3 Likes

Hey @mthorton,

That’s a clever way of adding a parameter to a function that doesn’t allow them.   :smile:

There is not a better way using that interface element.

If you’re an Alfred user it probably wouldn’t be too hard to create an action for it that passes a parameter to a KM variable and then runs the macro.

-Chris

That's a clever idea, and at first I was going to say no, but actually the answer is pretty close to yes.

First, the partial solution is that the %TriggerValue% actually gives you the text that was searched for (eg "timer 30" in this case).

Now the problem is that "timer 30" wont find your macro, but you can add a comment action with possible values.

And after that "timer 30" will match your macro. And then it is just a simple matter of using the Search action to extract the number.

3 Likes

I Would Like to see the finished product of this… Scratching my head on this one…

:smiley: :kissing:


That is basically finished except for doing whatever you want with the value. For example, you can use this macro, Trigger Macro by Name like "timer 10", it will pause ten seconds and then speak the specified text. The Comment is just so the numeric values (eg 10) still matches.

Timer via Trigger Macro by Name .kmmacros (2.7 KB)

2 Likes

**Thank you very much… :smile: **

My sincere thanks to @mthorton and @peternlewis for the concept and examples.

Based on your work, I have extended it in this macro, which shows the results of the trigger, and validates the “parameter” typed at the end of the macro name:

###Macro: Demo Use of Trigger “Keys” (Parameters) in Trigger by Name

1 Like