Functions
Shows how to make a macro that other macros call, with inputs and a result, and how to pull repeated steps out into one.
Keyboard Maestro: Execute a Subroutine, Execute Macro, Return Result
A function is a macro you call. There is no separate kind of thing to learn: any macro can be called with a Run macro step, and one that has no triggers and takes inputs reads as a function.
What makes a macro a function #
Takes are its inputs. Add one with Macro › Add Input (⌃⌘I). Each has a name, a type (text, number, yes/no, choice or file), an optional default and a description. An input with no default is required.
Gives back is its result. Choose Macro › Give Back a Result…, pick the type, and end the macro with a Return a value step. If the value is the wrong type, the call fails and says so: "Slugify should give back text, got a list".
The Functions item in the sidebar lists macros that have no trigger and either take inputs or are called by another macro. They stay in All as well.
A function gets its own variables. Only shared. variables carry over from the macro that calls it, so it cannot change the caller's variables by accident. To hand several values back, return a record and read them as {{result.name}}.
Calling one #
In a Run macro step, choose the macro from the list. The inspector then shows one field for each input the macro takes, with its default as the hint and required ones marked. Type {{ }} values as usual. Save result as names the variable that receives what it gives back. Turn off Wait for it to finish to start it and carry on.
If the macro you call changes, the step tells you: an input it no longer takes is shown dimmed with a Remove button, and a required input you have not filled in puts a warning on the macro. Renaming an input offers to rename it in every macro that passes it, in one Undo step. Deleting a macro that others call asks first.
Extract to Macro #
Most functions start as repeated steps. Select a step and choose Macro › Extract to Macro… (⌥⌘E), or use the step's context menu. Switchboard works out what the steps read (the inputs) and what later steps need from them (the result), and you confirm both. The steps move into the new macro and are replaced by a call. One Undo puts everything back.
Extract is off for steps that contain a Return, or a Break or Continue that belongs to a loop outside them.
Sharing, AI and agents #
Sharing a macro that calls others includes those macros too. The share sheet lists them ("Also shares Slugify"). Importing reuses a macro you already have when it is identical, and otherwise brings it in as a copy and points the calls at the copy.
Make with AI is told each macro's inputs and result, and is asked to call an existing macro instead of writing its steps again.
Agents see a function's inputs and result in
list_macros, if you expose it.In the palette, a macro with required inputs asks for them in a small form: Tab moves between fields and Return runs.
Debugging #
Activity shows a call as a nested run under its caller, and a failure inside the function says which step of which macro called it. In debug mode, F7 steps into the call and out again at its end.