A variables assigning issue

What I want to do is assign the following variables respectively:

variable Text_1 ← ABC_1

variable Text_2 ← ABC_2

variable Text_3 ← ABC_3

Although through the following macro it just gives me %Text% instead. It seems like it's something to do with the 'Process Text Tokens and return the result' ? I'm still not sure what's the problem after reading some related info such as What does "Filter Variable ‘Variable’ with Value of Named Variable" do? - Questions & Suggestions - Keyboard Maestro Discourse_2019-08-09

Can anyone help out here?

Keyboard Maestro 8.2.4 “variables assign” Macro

variables assign.kmmacros (27 KB)

You are NOT using the proper form of a KM Variable Token. It should be:

See How To Use Dynamic Variable Names.

@JMichaelTX Thanks for your time and replay! But it appears to me that's not the problem.

But after doing the following replacement, it works for now.

  • Filter Text “ABC_%varIndex%” with Value of Named Variable
  • Store result to Variable “Text”.


  • Filter Text “ABC_%varIndex%” with Process Tokens
  • Store result to Variable “Text”.

Anyway, Dynamic Variable Names has really been confusing me a lot. Thanks for the information that I need to dig into. Hope Soooo many % in a Dynamic Variable just won't dazzle me someday.:crazy_face:

Actually, the explicit %Variable notation is not strictly required, despite JMichaelTX's post, which is why it wasn't the problem. It's highly recommended, though. Anyway, I'm writing mainly to let you know (or remind you) that you can also use variables as arrays. For example, if the variable called TextArray has the value red&&orange&&yellow, then you can extract the values from that array using indices. Therefore,




Here, I used && as a delimeter, but you can set anything you want as the delimiter. I chose && simply because it's unlikely to occur in any text I want to load in my array.

1 Like

Cool, remind me of this Move mouse to previous location - Questions & Suggestions - Keyboard Maestro Discourse_2019-08-15

Got understand why it works after so many times of using. :blush:

Selecting that option will place the mouse pointer to the position it occupied before the macro moved it, so that position depends on where it was to start with. If you don't select that option, then the mouse pointer will stay where the macro puts it.

What I meant to say is that your array example has enlightened me to this mouse position macro.

I thought that might be the case. I wasn’t quite sure because of the wording. Anyway, arrays are quite useful. I use them (and the manipulation of text files in general) quite a bit.

Maybe that's because my English is not very good. :stuck_out_tongue: Please feel free to point out the problem if it has any.

I am correct in my above statement:

From the KM Wiki:
Variable token

You can also use a short form of just %Variable Name% to include variables ==as long as the variable exists and has a value and there is no corresponding text token==, although generally it is better and clearer to use the longer form %Variable%Variable Name% .

When you use the short form, you run the risk of getting unexpected results.
The only exception is when using Local or Instance variables, which always start with one of those prefixes. Then you can safely use the short form.

The macro and image in your OP has become corrupted somehow, but here is an example macro that basically does what you ask:


Example Output


MACRO:   How To Use Dynamic Variables [Example]

**Requires: KM 9+   macOS 10.11 (El Capitan)+**
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

#### DOWNLOAD Macro File:
<a class="attachment" href="/uploads/default/original/3X/d/f/df61fbcbf8a803beaf34a8993ead69805ba73cb7.kmmacros">How To Use Dynamic Variables [Example].kmmacros</a>
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**


### ReleaseNotes

Author:  @JMichaelTX

### Requirements

What I want to do is assign the following variables respectively:

variable Text_1 ← ABC_1
variable Text_2 ← ABC_2
variable Text_3 ← ABC_3

Although through the following macro it just gives me %Text% instead.


<img src="/uploads/default/original/3X/1/8/1849ae0af1a32dd7e8a938667139e6fa807fb5b6.png" width="627" height="865">


### Questions?

Thank you for the explicit information and it needs some time for me to digest that.