Keyboard Maestro 5

Conduct your Mac Like a Pro!

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.

- MILLISECONDS or MILLS or MS
- fractional milliseconds since startup.

- SECONDS
- fractional seconds since startup.

- NOW
- current time in seconds since the start of 1970.

- TIME
- time in 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.

- TIME2JD
- convert time from unix TIME to JULIANDATE.

- TIME2MJD
- convert time from unix TIME to MJD.

- JD2MJD
- convert time from JULIANDATE to MJD.

- JD2TIME
- convert time from JULIANDATE to TIME.

- MJD2TIME
- convert time from MJD to TIME.

- MJD2JD
- convert time from MJD to JULIANDATE.

- YEAR
- get the year component from a unix time (seconds since the start of 1970).

- MONTH
- get the month component from a unix time.

- DAY
- get the day component from a unix time.

- DOW
- get the day of the week (1 = Sunday, 7=Saturday) component from a unix time.

- HOUR
- get the hour component from a unix time.

- MINUTE
- get the minute component from a unix time.

- SECOND
- get the second component from a unix time.

- MOUSEX
- the x coordinate of the current mouse location.

- MOUSEY
- the y coordinate of the current mouse location.

- MOUSEBUTTON
- 1 if the corresponding button is pressed, 0 otherwise.

- SCREEN( n, Left|Right|Top|Bottom|Width|Height|MidX|MidY )
- screen frame coordinates.

- WINDOW( n, Left|Right|Top|Bottom|Width|Height|MidX|MidY )
- window frame coordinates.

- SCREENCOUNT
- the number of screens (displays).

- WINDOWCOUNT
- the number of windows in the front application.

- APPLICATIONS
- the number of running applications.

- IDLE
- the number of (fractional) seconds the Mac has been idle.

- ONLINE
- whether the Mac is currently connected to the Internet.

- BATTERY
- whether the Mac is currently running off battery power.

- SCREENSAVER
- whether the Mac is currently displaying the screen saver (or the display is off).

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.

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 example functions might be:

Amount in Dollars * 100 MJD() > 55928 NOW() > TIME(2012,3,23,12,2,1) DOW(2012,4,4) == 4 Radius*SIN(20°),Radius*COS(20°) Window Frame[1]+Window Frame[3]/2,Window Frame[2]+Window Frame[4]/2 MOUSEBUTTON() + 2 * MOUSEBUTTON(4)

© 1990 - 2010 Stairways Software Pty Ltd. All rights reserved.