A Keyboard Maestro Plugin for Apple Shortcuts

With the public release of macOS Monterey, I have been trying out a few ways of interacting with Shortcuts from a number of automation tools. Shortcuts can be triggered on macOS using AppleScript or shell script, both of which are relatively easy to do with the Swiss Army knife of Mac automation, Keyboard Maestro. However, I thought it would be fun to create a convenience plugin to make it even easier to integrate Keyboard Maestro with Shortcuts.

Installing the Plugin

Installing the plugin is very easy.

  1. Download a copy of the plugin.
  2. Ensure that the Keyboard Maestro editor is open and the dock icon is visible.
  3. Drag and drop the plugin ZIP file onto the Keyboard Maestro dock icon.

Using the Plugin

Once installed, you should see a new action listed in the Third Party Plug Ins category - Run Apple Shortcut.

When you add this action to a macro, you will see the following

Field Description
Name The name field is mandatory and is the name of the Shortcuts shortcut to be executed.
Input Type This drop down list has three options - None, Text, and File. It defaults to None, meaning that no input will be passed to the shortcut. When set to Text, it will pass the text in the action’s Text Input field to the shortcut. When set to File, it will pass the file for the path specified in the Input File Path field.
Text Input The text to pass to the shortcut if the Input Type has been set to Text.
Input File Input The path of the file to pass to the shortcut if the Input Type has been set to File.

Results can be set to output to any of the standard Keyboard Maestro options.

Example Use

Let’s walk through a quick example. We will start with a Shortcuts shortcut that takes some text input and then speaks it back to us, translated into French.

Now we have this shortcut, let’s see how we can use the plugin to set up a call to it. We know that the shortcut is expecting some text to translate, but where would we get the text from? Well, let’s use Keyboard Maestro to pass the current text selection to the shortcut.

Getting the selected text is something I use quite a lot in my Keyboard Maestro macros, so with v10, I set up a macro as a subroutine to make getting the current text selection even easier.

We can then use this in another macro to pass the selection via an instance variable into the shortcut action, which is set with Input Type “Text”.

For this example, I’ve given the macro a trigger of CTRL + OPT + CMD + 8. When triggered it calls the subroutine, which copies the text to a named clipboard, dumps that into an instance variable (in the subroutine), clears the named clipboard, and then returns the text to the original calling macro. That macro puts the text into an instance variable, which is used as text input to the translation shortcut which it calls. The result is a spoken translation of the selected text.

For example, each of the following successfully translated to “Bonjour, je m’appelle Stephen”.

  • Good Morning, my name is Stephen.
  • Guten Morgen, mein Name ist Stephen.
  • Buenos días, mi nombre es Stephen.

Summary

For me, this Keyboard Maestro plugin is a much quicker and neater way to write a macro to call a Shortcuts shortcut. It is certainly easier to read and maintain than some AppleScript or shell script, and adding in the entry and name of a shortcut is definitely very quick to do. But as I noted right at the start, this is very much a plugin of convenience - it is certainly possible to utilise shortcuts in Keyboard Maestro without using it.

Author: Stephen Millard
Tags: | keyboard maestro | shortcuts |

Buy me a coffeeBuy me a coffee



Related posts that you may also like to read