How Do I Clear a Placeholder Variable?

So if I set a variable named export to nothing then displaying %export% should show nothing. However it is showing %export%

I tried to use the AppleScript that I've seen but I couldn't get it to work. The alternative I can think of is to use multiple if statements to show when export is empty and when export is not.

I would prefer to not use multiple if statements. As if the code is not big already.

To display nothing for a variable that does not exist, you have to use
%Variable%export%

In fact, you should always refer to variables using "%Variable%" because if you don't, bad things like that will happen.

https://wiki.keyboardmaestro.com/token/Variable

I literally hate using %Variable%. For one, its redundant when I clearly know that anything between % and % is a variable. Secondly, It makes code in the macros harder to read. Long winded.
Perhaps if it was %var%Export%
but why type %var%Export% when I can just type %Export%

I treat %Export% like a placeholder vs a variable.

If it was redundant then it would be completely unnecessary. But it's absolutely necessary for some cases so it's not redundant.

That's incorrect. Here's an example that is not a variable: %LongDate%

1 Like

%LongDate% which @sleepy mentions is a Text Token, which is patently not a variable.

This is why you should always use the %Variable%Variable-Name% syntax for variables in text fields. Even though %Variable-Name% is supported by KM (unfortunately), it is all too easy to confuse a variable and a text token in a macro.

If you rigorously stick to the long format for variables it is impossible to make that mistake.

Tokens user manual section.

Yes – it's a trifle tedious to create the long syntax, but as many of us have you can create a macro to do that for you.

-Chris

2 Likes