"Index" of a variable created from the clipboard

Let's say I have this on a text file:

Text1
Text2

Now I select both and copy both to the clipboard, so now on the clipboard I have 2 lines and save that to a variable (Local__URL), with both lines. Now I would like to use Text1 in certain parts of my macro, and Text2 in others.

For example for a URL, I would have something like this:
www.url.com/%Variable%Local__URL[1]%
www.url.com/%Variable%Local__URL[2]%

I know that [1] and [2] are used for arrays, but I don't know the equivalent for variable lines? Or any other workaround?

"For each Line" action?

This won't help when I want to use a certain line in a URL action.
For example if I want to use the first line in a url:
www.url.com/Text1

I need to find a way to use a variable at the end of the url in order to pick the line in the variable.

The "For each line" assumes that I will apply the same action to all lines in the variable.
"For each line" > do this.

Which is not what I need.

The only way I see it working is by creating different variables for each line, but still, if I use "For each line", how do I tell KM that each line is a specific variable with a specific name? I would need it to be:
"Grab line 1 of variable ABC and convert it to a new variable with THIS name"
"Grab line 2 of variable ABC and convert it to a new variable with THAT name"

Even for this, I can't seem to understand how to achieve it?

Okay. At the moment in Keyboard Maestro you can do this by adding an extra Action to search the Variable for \n (line breaks) and replace with some character that won't be used in any of the text (I use ★ but you could use @@ or anything you want)

Then you can access that line directly using ★ as a custom delimiter, something like: %Variable%Local__URL[2]★%

@peternlewis has recently said that in the next version of Keyboard Maestro the Search and Replace step will not be needed and something like %Variable%Local__URL[2]\n% will work directly. (i.e. \n will work as a custom delimiter without having to first change it to some other text.)

Anyway, until that new version is released you can do what you want, something like the example below:

EXAMPLE Access Lines of Variable.kmmacros (4.0 KB)

2 Likes

If you already have the text copied (according to your directions) in the clipboard, you can do it this way as well.

Variables from Text File Copied to Clipboard.kmmacros (2.9 KB)

Pretty much the same as @Zabobon. Please give him credit for the solution.

KC

1 Like