Linebreak as Custom Delimiter for Variable Array?

Is it possible to use the linebreak as custom delimiter? wiki here.

I know I can use loop to read the lines in variables. But it would be nice to use linebreak as custom delimiter to quickly get a certain line in a variable.

To arrange elements in lines is easier for us to read and edit. But I don't know if it is possible to use linebreak as delimiters. In the example below, I use * as delimiter. The problem is that the variables (expect for the first line) now include the linebreak.

The 2nd, 3rd, and 4th elements have a linebreak before. The 1st does not have line break. I don't want any linebreak.

image

Result:

Nope. The delimiter must be a visible character, other than "%".

AFAIK, KM does not provide a direct method to get a specific line in a Variable.
Fortunately, this is easy to do with JavaScript.

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Example Output

image

MACRO:   Get Nth Line in KM Variable [Example]

-~~~ VER: 1.0    2020-08-07 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Get Nth Line in KM Variable [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


1 Like

Thank you so much, @JMichaelTX.
You're always ready to help!!!

Inspired by a post years ago (reading a line from a file in shell):

and the example here (reading a line from a variable in shell):

I managed to get to use Shell script to work:
image

I use line delimiting frequently, but I do so indirectly. First, I read the document to a variable. Then I regex \R and replace with ~@return@~. Then I can access, say, the 14th line as %Variable%Whatever[14]~@return@~% in any macro.

1 Like

I normally prefer JavaScript over Shell Scripts, but this is a case when a Shell Script can really shine by using the KM "With input from text".

This allows us to remove KM Variables from being embedded in the actual script.

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.


MACRO:   Get Nth Line in KM Variable Using Bash Shell Script [Example]

--- VER: 1.0    2020-08-07 ---
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Get Nth Line in KM Variable Using Bash Shell Script [Example] .kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


1 Like

I like all of your creative ways.
Thank you so much for showing me all these solutions.