[SOLVED] Reverse lines nor working as expected?

I have a variable with the text lines:
link3
link1
link2

If I use the filter "Sort Lines", I get (as expected):
link1
link2
link3

But when I use Reverse Lines, I get this:
link2
link1
link3

Is this a bug or am I missing something?

Also, @peternlewis, the manual could use an update here (manual:Filters [Keyboard Maestro Wiki]). It says
Sort, reverse sort, or shuffle lines
and maybe it could have the exact terms such as
Sort Lines, Reverse Lines, or Shuffle Lines
I think it would be clearer and even for SEO purposes it would help Google find this.

Reverse lines does exactly that; it reverses then. So in this case, the first line becomes the last, and the last becomes the first. I agree that the wiki entry is confusing since it says “reverse sort” which is not actually the case, and the action itself does not say that, but rather “reverse lines”.

3 Likes

I see. So basically it "mirrors" the results, right?
So if instead of 3 lines I have 5, then 2 becomes 4 and 4 becomes 2, 1 becomes 5 and 5 becomes 1. Correct?

If that's the case, is there a way to Reverse Sort?

1 Like

Many ways – for example, reverse the output of a sort.

1 Like

I don’t think I quite understand your example, but it doesn’t add lines, if that’s what you mean by “instead of 3 lines I have 5”... it just reverses the order of the existing lines.

If I understand your meaning by “Reverse Sort”, then it’s just a matter of reversing the lines, and then sorting them. See the example macro, and again, apologies if I’m not following what your issue is. I think I need more coffee. :sweat_smile:

EDIT: the example macro has the correct order of actions, sort and then reverse. I just wrote it wrong in my comment above. Off to get that coffee now :rofl:

Download Macro(s): Reverse sort example.kmmacros (3.5 KB)

Macro-Image

Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
  • The user must ensure the macro is enabled.
  • The user must also ensure the macro's parent macro-group is enabled.
System Information
  • macOS 13.6
  • Keyboard Maestro v11.0
1 Like

Perhaps the other way around ?

(a subsequent sort would lose any initial reversal)

Reversed sort.kmmacros (23 KB)

4 Likes

My original example had 3 lines, right? So when you said that it reverses the first and last lines, that could mean that it reverses ONLY the first and last. So if the variable was
3
1
2

it would become
2
1
3

but if I had 5 lines instead:
2
5
1
3
4

it would be
4
5
1
3
2
(only reversing the first and last lines)

That's why I said it mirrors the results (or as you said, reverses the order, without sorting), instead of "first and last" lines. The way you phrased it could be interpreted as ONLY reversing the first and last lines (regardless of the number of lines) instead of mirroring the lines. Does it make sense? :slight_smile: If not, don't worry. It's not relevant haha

And yes, sorting them first and then reversing is what I want. Basically, just sorting them alphabetically Z-A instead of A-Z.
I wish KM would have this as an option. It seems a bit counterproductive to have an extra action to do something that could be done in a single action. We could have both Reverse Lines and Reverse Sort.

Thanks for sharing that workaround.

1 Like

Yes, first sort, then reverse. I think @cdthomer is still looking for coffee... :wink:

2 Likes

Ah, poor phrasing then haha. I edited my initial comment with a correction.

What’s funny is the macro i shared was the correct way, sorting and then reversing, but I wrote it up wrong in my comments :rofl::rofl::rofl:

3 Likes

It happens to all of us when the brain is faster (or slower) than the hands... :wink:

2 Likes