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+Temp/2,Temp+Temp/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, and never use any thousands separators.
Keyboard Maestro’s expressions include precedence, nested bracketed expressions, many built-in 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
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 (^)
unary prefix operators (√, -, brackets)
square root, negation, sub-expressions.
a variety of functions.
numbers and variables or array accesses (5,$5A,0x50,8#007,Variable,Variable)
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
SINH, COSH, TANH, ASINH, ACOSH, ATANH
hyperbolic trigonometry functions
exponentiation of e.
LOG or LN
logarithm base e.
logarithm base 2 or 10.
integer ceiling or floor.
truncate or round.
Minimum or maximum.
random real number from 0 to, but not including, N (defaults to 1).
random integer number from 0 to, but not including, N.
MICROSECONDS or MICROS
microseconds since startup.
MILLISECONDS or MILLS or MS
fractional milliseconds since startup.
fractional seconds since startup.
current time in seconds since the start of 1970.
the time in (fractional) seconds since the start of 1970 when the macro was triggered.
the number of (fractional) seconds the Mac has been idle.
current time in seconds since the start of 1970.
JULIANDATE or JD
days (and fractions of days) since January 1, 4713 BC Greenwich noon.
days since the start of November 17, 1858.
convert time from unix TIME to JULIANDATE.
convert time from unix TIME to MJD.
convert time from JULIANDATE to MJD.
convert time from JULIANDATE to TIME.
convert time from MJD to TIME.
convert time from MJD to JULIANDATE.
get the year component from a unix time (seconds since the start of 1970).
get the month component from a unix time.
get the day component from a unix time.
get the day of the week (1 = Sunday, 7=Saturday) component from a unix time.
get the hour component from a unix time.
get the minute component from a unix time.
get the second component from a unix time.
get the number of seconds from GMT.
the x coordinate of the current mouse location.
the y coordinate of the current mouse location.
1 if the corresponding button is pressed, 0 otherwise.
SCREEN( n, Left|Right|Top|Bottom|Width|Height|MidX|MidY, p )
screen frame coordinates.
WINDOW( n, Left|Right|Top|Bottom|Width|Height|MidX|MidY )
window frame coordinates.
the number of screens (displays).
the number of windows in the front application.
the number of running applications.
the number oftabs in the front Safari window.
the index of the selected tab in the front Safari window.
whether Safari has currenlty finished loading the current tab.
the number oftabs in the front Google Chrome window.
the index of the selected tab in the front Google Chrome window.
whether Google Chrome has currenlty finished loading the current tab.
the date received of the currently selected mail message.
the date sent of the currently selected mail message.
the flag of the currently selected mail message.
the flagged status of the currently selected mail message.
the read status of the currently selected mail message.
the junk status of the currently selected mail message.
the was forwarded status of the currently selected mail message.
the was redirected status of the currently selected mail message.
the was replied to status of the currently selected mail message.
whether the Mac is currently connected to the Internet.
whether the Mac is currently running off battery power.
whether the Mac is currently displaying the screen saver (or the display is off).
current system sound output volume (0-100).
an integer that changes when the clipboard changes.
The JD, MJD, and TIME functions return the current date and time, or can take the date (year, month, day) or date and time (year, month, day, hour, minute, seconds) to return.
The YEAR, MONTH, DAY, DOW, HOUR, MINUTE, SECOND functions return the relevant component of the current time or the can take the a unix time (seconds since the start of 1970).
The SCREEN index can be 0 for the main screen, and then 1 through n are the screens in orientation order from left to right. The index can also be one of:
the screen with the menu bar.
the left most screen that does not have the menu bar.
the left most screen that is not the Main or Second screen.
the left most screen that is an internal screen (typically on a laptop).
the left most screen that is not an internal screen.
the left most screen containing the mouse.
the left most screen containing (the most of) the front window.
the left most screen not containing (the most of) the front window.
the second left most screen not containing (the most of) the front window.
The optional p parameter specifies a percentage of the width or height to offset by. Eg SCREEN(Internal,Left,10%) would be the coordinate of left edge of the internal screen plus 10% of the width of the internal screen. Offsets are always to the right and down, but negative offsets are allowed.
The WINDOW index can be 0 for the main focussed window, and 1 through n are the screens in Z-order (1 is usually the main window), or -1 through -n in reverse order.
IDLE time is based on the Human Interface (HID) system, and so notices only HID device activity like mouse movement or keyboard presses, not things like disk access or movies playing.
Some actions have one or two images, or refer to a window or some text, and calculations in those actions can include reference to some context sensitive functions:
the original font size during the Apply Style action.
Keyboard Maestro refers to points as strings with two values, like 12,34 and to rectangles as four values 12,34,56,78. You can reference these values are arrays (eg Variable would be 34 in either case), but for clarity, you can reference these values using dot notation: