While there isn’t an immediate option to integrate ChatGPT into Keyboard Maestro, you can achieve this on macOS Monterey by combining Shortcuts with the macro. In this blog post, I’ll show you how to do it.
There are plenty of AI-powered apps where you can enter your OpenAI API key and prompt them to perform tasks for you. However, I’ve found that my most frequent use case is using ChatGPT to improve the clarity of my prose while typing.
To make this work, we need to send a POST request with all the necessary information to the OpenAI API endpoint. If you’re not familiar with the terms I’ve mentioned, please bear with me. Essentially, you need a method to communicate with the server and request that it return the processed text to you.
The most reliable method is to use the Shortcuts action Get Contents of URL
, which enables you to parse the response and extract the message for easy copying back to the clipboard. I will explain how it works, but you can also download and install this shortcut directly.
Download ChatGPT - Keyboard Maestro Workflow.
The workflow above receives input from a Keyboard Maestro macro. You will need to enter the API key and the system prompt within the workflow.
Configuring OpenAI API Key
If you don’t have a developer account, you can sign up for one at the OpenAI Platform. They consistently release faster and more powerful models; however, the most cost-effective model available at the time of this post is chatgpt-4o-mini
, which we will be using in this guide. Create a project API key, name it “Keyboard Maestro,” and store it in your notes. The key enables communication with the server to process your request.
Expand the “Get content of URL” action, and you will see something similar to the screenshot below.
Enter the key in the Authorization
field, located within the Headers group. If you opened the shortcut above, you’ll see that the value has been set to CombinedOpenAI_API_KEY
for simplicity in configuration.
Combining Keyboard Maestro and Shortcuts
With the Keyboard Maestro macro, you want to pass the information you want to process into the Shortcut workflow you’ve just configured. You can choose to pass the “prompt” if you plan to create a different type of macro to process the text. Since we’re always processing the clipboard, there is no need to create another variable.
This is where you can choose where to store the prompts. The most straightforward method is to set KM_Input
as the value for OpenAI_Prompt
.
If you intend to process only the clipboard with the macro, you should pass the Clipboard
into the message. Once the workflow completes, it will copy the results to the clipboard.
The Get dictionary action
parses the values returned from the server. You don’t have to worry about this part because the API response rarely changes. If it does change, you’ll need to debug this section by checking what values it returns using the Quick Look
action.
Support my works, please?
I enjoy writing these guides so you can tap into the full potential of Keyboard Maestro, but I don’t want to offer a subscription or ask for donations. If you appreciate everything I have written so far, you can support me by purchasing this Keyboard Maestro collection called Keyboard Tyro.
It features a new macro group called ChatGPT - Clarity, where I integrate the techniques I’ve shared here with additional features, such as:
- Configuring the OpenAI API Key as a Keyboard Maestro variable.
- Utilizing the Keyboard Maestro Dictionary to pass multiple variables into the Shortcuts workflow.
- Easily creating multiple prompts with a single macro that serves as the logic for processing commands.