Is there a function for conditional token insertion?

I want to have an email signature that has an optional line in it to have text like “I’m going on vacation soon”. Is there a way to have a variable and a new line only inserted in text if the variable’s defined, or not empty, or something? I could so some if/then work or find/replace to make it happen, but I thought there might be a simpler way I’m overlooking.

And if I am overlooking something, an equivalent to an IF/THEN calculation for text values would be a nifty feature addition.

You could always insert the variable but only populate it if you want it to say something. So it would always print but it would print nothing if the variable was empty ("") and something (“Going on vacation soon.\n”) if it wasn’t.

Do you mean something like this, or would this not work for your needs?

No, there is no kind of If Then Else token conditional evaluation system.

@mrpasini is correct, the best and easiest solution is to ensure your variable is either empty, or has a new line at the end of it. Your macro could actively add the new line character to the variable if it is missing.

Technically, it is possible to do this in a token, but its way too much work to make sense as a solution. I've included a solution below in case there are ever situations where this kind of technique is really essential.

Keyboard Maestro Actions.kmactions (1.4 KB)

Well, if I understand you correctly, the answer would be yes. :smile:

If you are using KM to create/paste your email signature, you just need to add a KM variable after the signature. The KM variable would be your optional line. If you don't select and optional line, the KM variable will be blank.

So, you could have something like this (using a prompt since I don't know your workflow). Let's us know if this answers your question.

Example Output

###MACRO:   Providing Optional Line for eMail Signature

~~~ VER: 1.0    2017-10-28 ~~~

<a class="attachment" href="/uploads/default/original/3X/3/2/32d9d9c85117a0038112957bbd7d7fbd939d13b9.kmmacros">Providing Optional Line for eMail Signature.kmmacros</a> (8.4 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**


<img src="/uploads/default/original/3X/c/0/c03a79c722b6ecba2dd90ba417dedafcc92bc05a.jpg" width="474" height="1963">



Thanks, that pretty well confirms my own research. Appreciate the many suggestions on other approaches.