Keyboard Maestro 6
Conduct your Mac Like a Pro!
A Macro executes a sequence of Macro Actions in order. There are many actions to choose from, and these are detailed below. Some simple actions, such as Sleep Computer, require no other information and simply do their job, while other more complex actions, such as Select Menu Item, require you to specify more information, such as a target application or menu name.
There are many powerful Macro Actions available for your use, and you can sequence them together to perform complex tasks.
To add an action, edit your macro, click the New Action button, or equivalently the
button below the detail view. This will show the lists of possible actions.To see all actions, select the All Actions category. To select just your favorite actions, select the Favorites category. You can drag actions into your Favorites category. To see plug in actions that you have added to Keyboard Maestro, select the Third Party Plug Ins category.
Double click or drag one or more of the actions to add them to the action list for the currently edited macro.
Some actions are simple and do not require any configurion (eg Shut Down Computer). Other actions require you to specify parameters to the action, such as which window to move and by how much. You do this by editing the values for the action.
In Keyboard Maestro, there are two kinds of processed fields in actions, text token fields and numeric calculation fields. Most text fields are text token fields. Most numeric fields are calculation fields.
Text token fields typically (but not always) have an Insert Token pull down menu, and are always somewhat long. They are designed to allow you to enter a defined text item, rather than a numeric value. In these fields you use text tokens, which are marked with percents, like %CurrentClipboard% or %Variable%My Variable%. You can insert a text token from the Insert Token popup menu, or by choosing Insert Token from the Edit menu, see the Text Tokens section.
Numeric calculation fields are usually small to start off with (assuming they contain only a number), and usually have a stepper (double arrows) next to them. They are designed to allow you to enter a specific numeric value. In these fields, you can type a raw calculation. As soon as you type anything other than a digit, they expand to a larger size to allow for a calculation. Calculation fields never use percent tokens, but they can include variables or functions. You can insert a function or variable by choosing Insert Function from the Edit menu, see the Calculations section.
If desired, you can include a calculation in a text token field by using a %Calculate% token like %Calculate%1+2%. You can never use text tokens in a calculation field.
Application Control actions allow your to switch, quit, or hide applications. The actions are:
Clipboard actions let you manipulate the system clipboard, Named Clipboards, the clipboard history and cut, copy or paste clipboard items. The actions are:
You can control the flow of a macro execution using a variety of actions, from a simple Pause for a number of seconds, through a complex nesting of If/Then/Else and looping.
The actions to control the flow of a macro are:
You will often need to use the Pause action to slow down replaying of an action sequence to allow the system time to catch up—especially after you have changed applications or if you want to use a mouse click.
The condition clause of the flow control actions can be any of:
If there are no conditions in the set at all, the action will not execute anything except the Until action which will execute the actions once. Neither side of the If Then Else will execute.
There is over a dozen different kinds of conditions, from testing what the current application is or examining variables or the clipboard, to checking your network location or testing a pixel on your screen, see the Conditions section.
The For Each action loops over a set of collection items, setting a variable to each value and executing the contained actions. The collections can include:
The control flow actions include a nested list of their own actions to execute, and that nested list can include further control flow actions—go wild! But keep in mind, there may be a time when a shell script or AppleScript is a more useful way of describing your solution.
See also the Conditions, Variables and Calculations sections.
Keyboard Maestro includes a built-in Macro Debugger which allows you to observe and control the progress of a macro in action. As well as using the Macro Debugger normally, you can use any of these actions, triggered by any method you like, to control the debugger.
Note that regardless of whether a macro would otherwise be paused, these actions will always execute. So, for example, even if you have New Macros Paused, macros that start with these debugger actions will still execute the action.
See also the Macro Debugger section.
Mail Control actions allow you to interact with Apple Mail, send messages or set mail flags. The actions are:
Note that the currently selected mail message is not necessarily the front window, it may be a message selected in the viewer behind the front window, especially if the front window is a reply or new message.
Execute actions let you execute AppleScripts, shell scripts, Automator Workflows, JavaScripts or another macro. Shell scripts can be any kind of script: sh, zsh, tcsh, perl, python, ruby, and so on.
The actions are:
The results of an AppleScript, shell script or JavaScript can be:
For example, you could have a shell script date display briefly in the Notification Center every hour, or use a hot key to type the results directly into your text editor.
These powerful actions allow you to add any new facilities we have not provided for, stringing them together with other actions as desired.
You can also use the clipboard by piping from pbpaste and to pbcopy.
Shell scripts are executed in the background and can access variables by using environment variables, see the Variables section.
AppleScripts are executed in the background via osascript. This means they are not allowed to do user interaction. You can work around this by asking an application like System Events to do the user interaction for you, for example:
tell application "System Events" activate display dialog "Hello" end tell
AppleScripts can access variables by using environment variables (using system attribute) or by talking to the Keyboard Maestro Engine, see the Variables section. Note that AppleScript’s system attribute is not safe for international characters, although can use code like:
set v to do shell script "echo $KMVAR_Variable"
JavaScript can access variables by using the document.kmvar dictionary, see the Variables section.
It is a short step from executing a script action to writing some Plug In Actions.
File actions allow you to interact with the file system, moving, copying, duplicating, trashing or deleting files or folders. The actions are:
The source path must be an absolute path (or a home relative ~ path). The destination path must either be a simple single path component (not ~ or /) or an absolute path. If it is a simple path component, then it is relative to the parent directory of the source path. This is particularly useful in the Move or Rename action, as you can, for example, rename from ~/Folder/Old Name to New Name.
You can read or write files in a variety of formats, including PNG, TIFF, JPEG, as well as HTML, Web Archive, Word Document and more.
File attributes include:
You can control Safari or Google Chrome, including creating windows and tabs, moving tabs, and interacting with web pages. The actions are:
There are a number of Text Tokens to get various values from the web browser, including title, URL, ready state, a field value or the result of arbitrary JavaScript.
There are also a number of functions to get various values from the web browser, including the tab count, tab index, and whether the browser has currently finished loading.
Note that complex web sites often report that they have finished loading and then start loading again, which is why the action to wait for the browser to finish allows you to specifiy a required minimum time.
See also the Text Tokens and Calculations sections.
Image actions allow manipulations such as flipping or rotating images, or capturing the image of a window or screen. The actions are:
Image actions typically act on an image in the system or a Named Clipboard. You can read or write images files using the File actions.
Interface Control actions allow you to interact with the user interface, selecting menus, clicking buttons, simulating keystrokes and so forth. The actions are:
The various size and location fields can be Calculations.
The Manipulate Window action includes defaults for positioning a window in various columns or corners of a screen. This is a useful way to see some examples of calculations you can use.
The Move or Click Mouse has lots of options, including single, double or triple clicking, and where the click is relative to. If you record a mouse click, you can (for a short while) adjust the corner that the click is relative to and the values will adjust accordingly. You can also perform a click and drag with this action.
The Select Menu Item action lets you choose from all currently running applications and their menus, which helps ensure you have correctly specified the menu. If you leave the menu item blank, Keyboard Maestro will show you the menu and let you then select it manually.
The Select Menu and Press Button actions allow you to specify multiple options separated by a vertical bar (eg Show|Hide) to allow for toggling menus. They will also ignore the difference between three dots (...) and an ellipsis so you do not have to worry which one the menu uses. Alternatively, you can start the name with an ^ and use a regular expression to match the menu or button name. Also, Select Menu will translate the word "APPLICATION" (all capitals) into the current application name, allowing menu selections like APPLICATION -> About APPLICATION.
The Select Menu and Press Button actions will, by default, abort the macro if the action is not successful (for example if the button or menu cannot be found or is disabled). The action can be configured to allow the macro to continue if the menu or button is not essential (such as “Mark As Read” which might be disabled if the item is already marked as read).
iTunes Control actions allow you to interact with iTunes, playing songs, stopping or pausing, rewinding or fast-forwarding. All actions will launch iTunes if it is not already running. The actions are:
These actions allow you to control how Keyboard Maestro behaves. The actions are:
Trigger Macro by Name allows you to trigger any active macro by name. By default, Keyboard Maestro creates a macro triggered by Command-Control-Option-T or the status menu which triggers a macro by name.
Recording allows Keyboard Maestro to watch you as you perform a task and create the actions to produce a similar result.
Record Quick Macro is a variant of this that you can activate at any time without launching Keyboard Maestro. You trigger the recording, and then perform a series of actions, and then turn off recording. Then press the associated hot key to replay the recording.
By default, Keyboard Maestro creates a macro triggered by Control-F1 which executes the Record Quick Macro action with a hot key of Option-F1. So for example, if you press Control-F1 to start quick recording, type “hello” and then press Control-F1 again to finish recording, then Keyboard Maestro will type “hello” each time you press Option-F1.
Because you cannot see or edit the recorded actions, it is best to keep them very simple. A good rule of thumb would be not to touch the mouse, just use the keyboard.
For example, say you wanted to quote a dozen different words in a paragraph, you could click in the middle of the first word, press Control-F1 to start quick recording, type Option-Left Arrow, quote ("), Option-Right Arrow, quote ("), and then Control-F1 again to finish recording. Now click in the middle of each remaining word and press Option-F1.
The Set Macro or Group Enable action allows you to enable, disable or toggle the enable of a macro group or macro. The Keyboard Maestro editor does not need to be running, but it will see the enable state when it is next launched (or immediately if it is already running).
If you hide the global macro palette, it will remain hidden until shown. You can also hide the global macro palette by clicking the close icon, so you may wish to include a global macro, perhaps with a status bar trigger, which uses the Show Macro Palette to redisplay it.
Send a MIDI message:
The MIDI messages come from a device named “Keyboard Maestro” which will be created as soon as you add any MIDI action.
Keyboard Maestro can notify you in a variety of ways:
Open actions allow you to open files, folders, URLs or System Preference Panes. The actions are:
Files, folders, the Finder selection and URLs can all open either in their default applications, or a specific application. So you could, for example, create a macro that opens the Finder selection in BBEdit.
QuickTime Player Control actions allow you to interact with QuickTime Player, playing movies, stopping or pausing, stepping forward or backward, or adjusting the volume. All actions will launch QuickTime Player if it is not already running. The actions are:
Keyboard Maestro includes several powerful switchers, including Application Launcher, Application Switcher, Window Switcher, and Copy, Cut and Paste Clipboard Switchers and Clipboard History Switcher.
Each of these switchers is actually just a macro action, triggered like any other macro. By default Keyboard Maestro creates a Macro Group called Switcher Group which includes the following macros:
You can create your own macros using these actions or adjust their triggers within the Switcher Group.
By default, Keyboard Maestro overrides Command-Tab and the system application switcher. If you wish to use the default system switcher with Command-Tab, you can do so by disabling Keyboard Maestro’s macro or by changing its hot key trigger.
System Control actions allow you to control your Mac. Most are pretty self-explanatory. The actions are:
Some of these actions require particular hardware support and so may not work on all Macs.
Most of these actions are covered in their respective sections (eg Set Clipboard to Text is covered in the Clipboard Actions section).
The Insert Text action deserves special attention as it allows you to insert specified text by
For inserting text by typing, the text may include non-ASCII characters as long as they can be typed on the keyboard with one or two keystrokes.
The Display Text action allows you to display the resulting text in a floating window or Notification Center.
Tokens are provided to include variables, calculations, the time or date, and a large variety of other system information.
The Insert Text action can be very useful to insert standard text templates, such as your signature, address, copyright or other boilerplate text, and so on. If you ever get email from Peter, you will probably notice that many of his emails end with “Thanks for your support, Peter.” – with the amount of email he deals with, you don’t think he types that in every time, do you?
Insert Text can expand various tokens, including dates in any ICU date format. For example you can use an Insert Text action to insert the copyright message at the top of code files:
/* * Created by %UserName% on %ICUDateTime%EEE d MMM yyyy%. * Copyright (c) %ICUDateTime%yyyy% Stairways Software. All rights reserved. */
There are three ways to type text in Keyboard Maestro: Insert Text by Typing, Insert Text by Pasting, and Type Keystroke. A common question is when should you use each?
The Type Keystroke action lets you type a single keystroke, pretty much any kind of keystroke you can type on the keyboard.
The Insert Text by Typing action converts plain (simple) text into keystrokes and then types each of them individually. It only works with characters that can be typed on the keyboard with one or two keystrokes (eg Option-e e usually types é, and Keyboard Maestro can duplicate that typing).
The Insert Text by Pasting action sets the clipboard to the (optionally styled) text and then types a Command-V keystroke.
Each action has its advantages and disadvantages:
The Type Keystroke action is just like typing yourself, so you can type any keystroke and any number of them, but it can be tedious to create a sequence of keystrokes in a macro.
The Insert Text by Typing action is also just like typing yourself, similarly permitting characters like tab/return and maintaining the current style in the program into which you are typing, but it is slow for large amounts of text and can't type exotic characters like Emoji.
The Insert Text by Pasting action is fast for large text and can include any kind of characters, as well as styles like bold and italic, but it overwrites your clipboard and its handling of styles may occasionally not conform to your expectation.
So you should use Type Keystroke when:
Use Insert Text by Typing whenever:
Use Insert Text by Pasting when:
See also the Text Tokens section.
Keyboard Maestro includes permanently stored variables that you can use in a number of special purpose actions, as well as in Calculations or Text Tokens which can be used in almost any field in Keyboard Maestro. These specific actions let you manipulate variables:
The Use Variable action can perform the following actions:
Most of these have analogs in the Text Tokens, so for example you might do:
Set variable ‘Temp’ To Text ‘%FrontWindowFrame%’ Set variable ‘Temp’ To Calculation ‘Temp[1]+Temp[3]/4,Temp[2]+Temp[4]/4’ Use ‘Temp’ to Set the Mouse Location
Which will result in the mouse being placed in the middle of the upper left corner of the front window.
Search Variable will use a regular expression to pull apart a variable, allowing you to extract the various parts. It displays the results live in the editor, allowing you to construct complex regular expressions more easily.
See also the Variables, Text Tokens and Calculations sections.
Prompt For User Input will allow you to ask for user input, storing any results in variables as designed. If the variable is a password variable (ie, its name starts or ends with “Password” or “PW”), it will be displayed in a password field.
If the default value you specify consists of choices separated by a bar (|), then a popup menu will be used (the first value will be the default value, and can be repeated later if a different location is desired). For example “Better|Good|Better|Best” would result in a popup menu with Good, Better, and Best, with Better pre-selected.
If a component of a popup menu item is a dash (-), then a separator is displayed. For example, “Good|Better|Best|-|Terrible”
If a component of a popup menu item starts with a prefix followed by two underscores, then the prefix will be used as the variable value, while the latter part will be displayed in the menu. For example, “B__Good|F__Fail|C__OK|B__Good|A__Excellent”.
If the field starts with a bar (|), then token expansion happens first, followed by separating by bar (|) - this allows you to have a variable list of entries, for example, “|This|%Variable%Multiple Entries%”. Otherwise, the entry is separated by bar first, and then token expansion is applied to each field, so that fields may contain bars, for example, “This|That|%Variable%One Entry%”.
If the popup menu would contain only "0" and "1", then a checkbox is used (so for example, “0|1" or "1|0", depending on the desired default).
If the variable name starts with a prefix followed by two underscores, then the label will show only the latter part of the variable name (for example, MyMacro__Text Message will display a label of Text Message).
You can include one or more buttons, which may optionally cancel the macro. You can also include /«letter» to configure command keys for the buttons (/. means escape, / by itself means the default button) (for example, “Help/H”. If there are no text fields in the dialog, the command key is not needed and the letter by itself will complete the dialog. The name of the button pressed will be stored in the Result Button variable.
See also the Variables section.
You can open a URL in your default browser or a specified alternative and you can have Keyboard Maestro query you for a search term and then search a specified web site (by default Google).