Trying to understand the use of variable to text action using tokens

In the example below taken from KM Wiki the variable CurrentTitle is defined as the token %SafariTitle%.

Why bother define a variable ? Why not just directly use %SafariTitle% in the actions of the macro ?

Example:
image

thanks in advance for your time and help

Yes, absolutely. Most often you can just use the Token directly.

But sometimes it can be useful to save the Token to a Variable for use later in the Macro for the simple reason that Tokens are a kind of "snapshot" of of value at the point they are used in the Macro and Variables remain unchanged until you change them.

1 Like

Thank you very much. Do I understand correctly

  • tokens reflect a value at the time they are used ("real time")
  • variables reflect a value at the time they are defined, ie if defined 10 years ago, they reflect the value of the token at the time (not now). In the case in my post above, does CurrentTitle reflect the title of the safari front page, for example, 10 years ago when the variable was defined ?

Yes, exactly. Of course if your Variable was a Local Variable it would lose the value at the end of the Macro run but it would still have retained the value until you set it to something else in the Macro.

But also, in your example you are setting CurrentTitle to %SafariTitle so, every time that Action is run it will capture the title of the current Safari window. It would only retain the value until the Action was run again.

Sorry, what is a local variable ? thank you

Hi @Ronald. The different kinds of KM Variables is a fundamental part of the way Keyboard Maestro works and it is really worth reading up on them.

Any variable names with Local (any case) at the head of its name is a "local variable" and its value gets forgotten at the end of the macro run.

By chance a great video was just posted recently:

2 Likes

Your excellent replies and the video are EXACTLY what I was looking for. Thank you very much !

2 Likes