BUG Report -- Prompt with List Multi-Select Macro (v9.0.5d1)

,

Bug

When using "Allow Multiple Selections" option with a Prompt with List, if multiple items are selected then an extra LF is added to the last item.

Running Keyboard Maestro 9.0.5d1 on macOS 10.14.6 (Mojave).

Example Output

Source Action
image

When ONE Item is Selected, NO LF is added
image

When Multiple Items are Selected, a LF is added
image

Below macro provides reproducible behavior.

MACRO:   BUG Report -- Prompt with List Multi-Select

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

DOWNLOAD Macro File:

BUG Report -- Prompt with List Multi-Select.kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


If I am understanding you, that is working as designed.

Basically, if the answer is “one”, then the action will return “one”, but if the answer is “one” and “two”, then the action will return “one\ntwo\n”.

If it returns multiple lines, all lines have a line ending. If it has just a single line, there are no line endings.

It may be how you designed it, but, with all due respest, it is a poor, inconsistent design.
It leads to three lines of output, with the last being empty. Thus any processing of output has one empty item.

This is NOT how list or arrays work anywhere else.
If I select two items in an AppleScript Choose from List, it just returns two items.
If I convert an AppleScript list or a JavaScript array to text using "\n" it does NOT put an LF after the last item.

Please correct this design.

No it doesn’t. It has two lines, both with line endings.

For example:

image

The initial action has two returns, one at the end of each line.

The For Loop, even with Include Blank lines, logs only two entries - there is no blank line at the end of the file.

The shell command wc -l, fed the same data, reports two lines.

Historically, text files always end with a line ending. That line ending does not result in there being one extra blank line at the end. Generally speaking, such a file, without a line ending character at the end of it would be considered an error and could easily result in incorrect results.

Text with five lines, with five EOL characters at the end of each line, has five lines, not six lines with a blank line at the end.

If you are in AppleScript or JavaScript, and you have an array, and convert it to a string, how that is done will affect the results. Both AppleScript and JavaScript have ways to map an array to a string by adding delimiters. In JavaScript’s case, toString uses a delimiter of “,”. In AppleScript’s case, the default text delimiter is an empty string. Neither case turns an array of lines in to test, and sure, if you join an array and use an end-of-line character as a delimiter, you'll be one shorter than normal, because that is a join operation, which is a different thing.

1 Like

Actually that is incorrect. Both \r and \n are considered "new line characters". This is also how Regular Expressions identifies these metacharacters.

This is specific to KM. You must be trimming the string before writing to the file.
You have also done special processing to the FOR EACH Action to handle a newline as the last character in the string.

==That's the problem.
This data is NOT for a text file -- it is a list of items,== for which you have used LF as the delimiter.

As you know, any delimited list, whether by LF, CR, TAB, or COMMA, never has the delimiter at the end of the list.

I just tested this in both AppleScript and JavaScript. If I send the results of a multiselection KM Prompt from List to either script, and convert to a list or array, it results in the creation of an extra, empty array element at the end:

image

Even with a "text file", BBEdit counts an empty line as a line:

Please change the behavior of the KM Prompt with List to be consistent with every other tool that uses lists or arrays.

Here is my test Macro that outputs to AppleScript and JavaScript:

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

Example Output

image

MACRO:   BUG Report -- Prompt with List Multi-Select with Scripts

**Requires: KM 9.0.2+   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/1/c/1c87760b77b6cca82619b457275c7811dce99172.kmmacros">BUG Report -- Prompt with List Multi-Select with Scripts.kmmacros</a>
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**


---


<img src="/uploads/default/original/3X/0/b/0b258d3e0d6fd11797b15fba895e8dab4285ee17.png" width="617" height="1724">