Keyboard Maestro provides two means to get information about objects (like web pages and windows) in the user's environment:
You can enter a Token in any text field in an Action, and when the Macro is triggered and the Action is executed, the token will be replaced by the value that is returned at that time. This allows you to easily combine static text with dynamic data that is supplied when the macro is executed, in most any Action that has a text field, like Display Text and Set Variable to Text actions.
Tokens are identified by a pair of percent
% symbols at the start and end of the Token name.
The available tokens, and their definitions, are listed on the Token List page.
When you are editing a Macro, put the text cursor in a text field, and do one of the following to select and insert a Token into the text field.
You can tell that a text field accepts tokens because a small T shows in the field while editing it.
Let's look at a real-world example. Let's say you would like to set the Clipboard to a Markdown Link of the current web page you are reading. All you need to do is insert these two tokens (using the Markdown format) in a Set Clipboard Action:
()” are just characters you type, part of the markdown text and not part of the tokens.
After the macro and Action are executed, you will see something like this on the Clipboard:
[Keyboard Maestro: Work Faster with Macros for macOS](https://www.keyboardmaestro.com/main/)
That's all you need for a great macro, which you can create yourself or download from here.
The Tokens are processed, that is replaced by their value when the action is run, and the Action containing the Token is executed.
In most text fields, you can control how Tokens are processed using the Gear ⚙ popup menu:
An exception to the rule of enclosing Tokens in percent
% characters, is the use of these Non-Printing Control Characters
\a,\b,\e,\f,\t,\r,\n which correspond to (bell,backspace,escape,form feed,tab,return,line feed). These will be replaced with their value in text fields, except for Regular Expression (RegEx) fields.
Text token fields also process %NN% or %NNNN% or %NNNNNN% as arbitrary hex unicode characters (eg %41% is an A, %01F300% is 🌀).
To include a percent in your text, simply double the percent (%%). To include a backslash \ in your text, double the backslash (\\).
Text fields also support text case conversion using the below meta characters. You may use these in both standard Text Fields and in the Replace field of a Search and Replace by regular expression action (even though these meta characters are not supported by ICS Regular Expressions).
The Available Case Conversion Meta Characters are:
\Uconverts everything up to the next
\Lconverts everything up to the next
\uconverts the next character to uppercase.
\lconverts the next character to lowercase.
\U\llowercase first, then uppercase.
\L\uuppercase first, then lowercase.
\Estop changing case.
You should not use
\L unless you terminate the sequence with
With tokens that return a list of information (comma separated by default), you can access the individual items using the Variable array notation, append the item number in square brackets
[ ] to the Token name, just before the closing
Token for Window Frame, %WindowFrame%1%, will be the third comma-separated value, which is the Window width in this case.
Some tokens that allow indexing include: