If Then Else Conditions Not Working as Expected

I want the IF THEN ELSE section to work similarly to this:

if ( (a == value1 || b == value2 || c == value3) && d == value4)
// Execute task 1
// Execute task 2

Basically if either/any one of the first 3 conditions are met AND in combination with the last condition evaluate to true; then perform task 1. If not, then perform task 2

I thought I'd understood how this would translate using KM but maybe not. Or perhaps I need a cast operation to evaluate the values as being numerical? Because values 1, 2 and 3 correspond to -13.0, -14.0 and -16.0 respectively.

I'd initially thought it was working until a value of -14.3 was passed in and it executed Task 1 when it should have fallen into the else block.

So either I need an explicit cast for the values OR it's evaluating based on ANY of the conditions being true. E.g. d (Local__AVGDynamics >= -9 which is not what I want.

What should I be doing to have ANY of the first set of values evaluated AND the last value being true???

Bounce and Process Audio File Ver. 3.kmmacros (36 KB)

Keyboard Maestro conditions only have "all of these" or "any of these" as options, so you cannot directly implement:

(a == value1 || a == value2 || a == value3) && d == value4)

in an If statement. You have it configured to "any of these", and thus any time AVGDynamics is >= -9 it will do the first one and the Integrated value will be ignored.

You could do something like “any of these”

a = value1 AND d = value4
a = value2 AND d = value4
a = value3 AND d = value4

But, since they are calculations, and calculations include AND and OR and bracketing, you can implement them directly in a calculation.

If calculation:

(Local__Integrated = -13 OR Local__Integrated = -14 OR Local__Integrated = -16) AND Local__AVGDynamics >= -9

Do note that = and floating point numbers are not a great combination. It may work for your case, but 1 != 1.000000000000000001, and floating point numbers make it very easy to get such cases.

1 Like

Hi. Thanks for the recommendation but I'm a bit confused. Where would I place that calculation within KM? Attempting to do as you've suggested results in the calculation being in red text suggesting that the value I've entered isn't valid. :face_exhaling:

Btw, the existing if then condition is already set to use "any of these"

Nevermind, I think I've figured your suggestion out. I just need to change the if then condition to evaluate a calculation. I'll give it a try. Thanks

1 Like

Yes, sorry, I should have linked to the Calculation condition.