Is it possible to pass variables between macros?

No code or example.
I just have a very generic question being can the variables set in one macro be passed to another macro without use of any hacked method requiring user input?


Macro A has set variables x, y and z
Macro B requires use of values of variables already set in Macro A

So psedo-code would look like:

Macro A (param x, param y, param z)

Possible with KM?

You can use global variables to pass values between macros or, better still, make Macro B a subroutine that takes the 3 local variables as parameters.

You can read about variables here manual:Variables [Keyboard Maestro Wiki]

And the manual about subroutines is here Subroutines [Keyboard Maestro Wiki]

Looks to me it is. Search in the manual for global varables[]=global&s[]=variables

Thank you, that info is very helpful. The global variable route was something I'd already considered but I'm not really that fond of going that route for what I have in mind.

That said, the Subroutine sounds more in alignment as to what I'd like to do. Only problem is that the link you provided seems to present much more than of a summary as opposed to how it's used.

In version 10.0, Keyboard Maestro adds an explicit Subroutine trigger which lets you specify the parameters by name, and whether the macro returns a value via the Return from Subroutine action. Such subroutines are called with the Execute a Subroutine action.
Note that parameters are internally passed by index, so if you later change the Subroutine trigger, and add or remove parameters, or change the meaning of parameters, you will need to adjust the various Execute a Subroutine actions as well - you can get to them directly using the Callers menu in the trigger.

Which in most cases I've found summary info to be adequate enough for me to start a venture except pulling in a "Execute a Subroutine" action into my macro doesn't appear to provide much of anything for me to manipulate. Option of none is the only option so it seems a tad confusing.

I'll search the forum to see if I can find any examples of implementing this component


If you want an example have a look at this thread

It is a fully documented subroutine macro together with an example macro that calls it. There are others to be found such as this one

Which also gives a subroutine and an example macro that calls it.

I’m away from my Mac so I can give only limited help, but let us know how you get on anyway!

Thanks, I've been dabbling around with the trigger options and noted the subroutine with parameters option so I believe I'm slowly grasping the concept in KM logic but I'll definitely review those example links you provided as well.

Clear as mud right now but I'll get there. :slightly_smiling_face:

Thanks @tiffle

I figured it out just seconds after my last response. Basically to accomplish what I want; setting any macro as a subroutine appears to be easily accomplished by setting the trigger type to "Executed as a subroutine with parameters"

I can then pass the variable of the main macro to the subroutine as a parameter.
I'm thinking I could just as easily pass the variable as a collection if I wanted to pass more than a few but this is fantastic and just what I needed. :+1:


Well if you get to the point of creating something and it somehow doesn’t work the way you wanted, do post here and you’ll get help!

1 Like