Keyboard Maestro 8.2.4 “Getting top line only of list” Macro

I'm trying to get ONLY the 1st line of a list from the clipboard and put it to a variable.
I'm not familiar with all the Reg expressions, but i have an idea putting in the right one, will make it work. Ideally i'd like to try to avoid the For each action.

Keyboard Maestro 8.2.4 “Getting top line only of list” Macro

Getting top line only of list.kmmacros (3.4 KB)

This is how I'd do it:

Test get first line.kmmacros (3.8 KB)

Hope that gives you some ideas. (BTW you don't have to use the system clipboard, I just used it for convenience..)

I've managed to figure it out, without using For each.

My bad - I missed that you wanted to avoid the very thing I was recommending :face_with_hand_over_mouth:

I'm not sure why you're using the search and replace action. Here's another approach with an overall simpler regex:

The (.*) works because of the way KM only returns the first match it finds.

1 Like

For the sake of completeness (not to mention keeping up my reputation), I'll offer another alternative.

If you wanted to use a shell script, you could filter the clipboard through the shell command

head -1

Usually head will give you the top 10 lines, but if you add -1 it will limit that to just the 1st line.

1 Like

Awesome thanks. Many ways to skin a cat, they say :slight_smile: