Making this trigger shorter

Using this script from KMF.

The only thing I need is to reduce the =calc=(.*)=
to =c in the front of the calculation and ? at the end

1 Like

You could change the typed string trigger to =c(.*)\? and also the second action's regex search to the same. Note that the ? you actually type when triggering the macro has to be escaped \? in both expressions because ? is a special character in regular expressions.

Changed it to this, just deletes the typed string and produces nothing. Appreciate your help.

Does the calculation need to be entered in brackets

No, but it shouldn't hurt and you can include brackets to set operator precedence -- the only issue might be that you pause too long hunting for characters and KM aborts the typed string trigger. But in that case it wouldn't do the deletion either.

This certainly works for me in eg BBEdit or in this editing window. I can't see any obvious differences, but give it a try instead of your version:

Calculate.kmmacros (2.6 KB)


Thank you both for this—I had never noticed the Calculate filter before. I've reworked the macro into something that fits my needs, where I select the formula before triggering the macro.

One thing you may consider is filtering the expression to be all uppercase before calculating. Keyboard Maestro won't calculate, for example, sqrt(2), but it will calculate SQRT(2). The Uppercase filter lets you type it either way.

1 Like

Top tip there from the ever-perceptive @drdrang.

Using two "Filter" actions in a row is a bit boring though, and I've never looked case conversion tokens. So...