User Tools

Site Tools


manual:Variables

Variables

Keyboard Maestro includes permanently stored variables that you can use or set in many actions, as well as in Calculations or Tokens which can be used in almost any field in Keyboard Maestro.

Variable names must start with a letter, and then can contain letters, numbers, spaces, or underscores. Variable names are case insensitive, but their case is remembered. Variable names should not include a function or operator name with spaces around it (eg “ MOD ” , so “A MOD B” would not be a valid variable, although “MODULE” would be fine).

Variables with names that start or end with “Password” or “PW” are considered passwords – their values will not be stored (except in memory) and they cannot be read directly by shell scripts or AppleScripts, though their consequences can easily be extracted, eg with the Set Clipboard to Text action. The Prompt For User Input dialog will display such variables in a password field.

Variable values are text, but they can contain comma separated numbers, and can then be accessed as arrays (eg Variable Name[1]). Mouse positions, window frames and the like can then be stored and manipulated in variables, and you can access the fields with “struct” like forms like Variable Name.width (field names include: x, y, left, right, top, bottom, width, height, midx, midy, and fuzz).

Variables values can be accessed from shell scripts or JavaScript for Applications via environment variables, and from AppleScript via environment variables or using AppleScript commands to the Keyboard Maestro Engine, and from JavaScript using the document.kmvar dictionary, see the Scripting section.

You can also set a variable value to %Delete% to avoid having it show up in variable popup menus. This is also a good idea to do after a variable has contained sensitive information (like a password) or a large value (like a file or web page contents).

There are various variables used by Keyboard Maestro to convey information, including:

Alert Button the name of the button clicked in an alert
Result Button the name of the button clicked in a Prompt For User Input dialog

Note that these variables can easily be overwritten by other actions, so you need to use caution when depending on them.

The following special variables were:

Mounted Volume Name replaced by the %TriggerValue% token
Mouse Click Result replaced by the %ActionResult% token
Press Button Result replaced by the %ActionResult% token
Select Menu Result replaced by the %ActionResult% token
USB Device Name replaced by the %TriggerValue% token

You can add a variable to an action using the Variable command in the Insert Function sub-menu in the Edit menu or Variable command in the Insert Token sub-menu in the Edit menu, or by selecting from the popup menu next to some variable fields, or by using Type Completion.

Variables are created on demand, but you can add, delete, see or change variables in the Variables preference pane, and you can read and write variables from AppleScript, see the Scripting section.

manual/Variables.txt · Last modified: 2016/06/27 02:45 by peternlewis