Keyboard Maestro 5 IconKeyboard Maestro 5

Conduct your Mac Like a Pro!

Calculations

Keyboard Maestro supports calculations in almost any numeric field. For example, you can Pause for 60*Time in Minutes. Calculations can also use comma separated lists of numbers as arrays, and can return such arrays, so you can operate on frames and points, for example:

Set variable ‘Temp’ To Text ‘%FrontWindowFrame%’
Set variable ‘Temp’ To Calculation ‘Temp[1]+Temp[3]/2,Temp[2]+Temp[4]/2’
Use ‘Temp’ to Set the Mouse Location

will result in the mouse being placed at the center of the front window.

Unfortunately, because of this you must use commas for this purpose, and full stops (.) for decimal numbers, regardless of your desired language.

Keyboard Maestro’s expressions include precedence, nested bracketed expressions, many inbuilt functions, various numeric bases, so you should be able to write most expressions you might like to use, as well as use it as a general purpose calculator if desired.

Operators based on precedence from lowest to highest are:

array separator (,)
separates elements of an array.
ternary operator (?)
a==b ? 3 : 4.
bitwise or (|), bitwise and (&) and bitwise xor
operators.
comparison operators (<, ≤, =, >, ≥, ≠)
compare for (in)equality and return 0 or 1.
shift operators (≪, ≫)
shift a number left or right.
addition operators (+, -)
add or subtract.
multiplication operators (*, /, MOD)
multiply, divide or mod.
power operator (^)
exponentiation.
unary prefix operators (√, -, brackets)
square root, negation, sub-expressions.
functions
a variety of functions.
numbers and variables or array accesses (5,$50,0x50,8#007,Variable,Variable[5])
identifiers and values.
unary postfix operators (!,%,°)
factorial, percent, degrees.

To minimize conflict with variables, operators and functions must be in uppercase.

Supported functions include:

SIN, COS, TAN, ASIN, ACOS, ATAN, ATAN2
trigonometry functions
SINH, COSH, TANH, ASINH, ACOSH, ATANH
hyperbolic trigonometry functions
EXP
exponentiation of e.
LOG or LN
logarithm base e.
LOG2, LOG10
logarithm base 2 or 10.
ABS
absolute value.
CEIL, FLOOR
integer ceiling or floor.
TRUNC, ROUND
truncate or round.
MIN, MAX
Minimum or maximum.
RANDOM
random real number from 0 to, but not including, N (defaults to 1).
RAND
random integer number from 0 to, but not including, N.
MICROSECONDS or MICROS
microseconds since startup.
NOW
seconds since the start of 1970.
JULIANDATE or JD
days (and fractions of days) since January 1, 4713 BC Greenwich noon.
MJD
days since the start of November 17, 1858.

Some example functions might be:

 Time in Minutes * 60
 MJD() > 55928
 Radius*SIN(20°),Radius*COS(20°)
 Window Frame[1]+Window Frame[3]/2,Window Frame[2]+Window Frame[4]/2

Continue on to Conditions

Close

Feedback Form

Please provide any feedback you may have


Email Address:
Subject:
Feedback:


Your email address is appreciated but is not required and will not be saved.
It will be used only for responding to or clarifying this feedback.

Documentation

Old Documentation