Select up to blank line in TextEdit

Hello, I'm trying to select text from the cursor up to the next blank line in order to then copy the text. There is no keyboard shortcut (that I know of) for this. Is there a way to get KM to select text up to the next blank line? (There are CaRs throughout the text, so it does need to be BLs).

Thanks!

Assuming your text is something like this, with blank lines in-between each block?
image

Those blank lines are in effect a return followed by a return. So, that is something that can be used.

⇧⌘↓ will select all from the current cursor to the end of all the text.

That can be copied and put into a Variable (in my example, called LOCAL__Variable)

The double returns in LOCAL__Variable can be replaced with something else that Keyboard Maestro can use to split up the variable into numbered chunks - I changed them to @@

The first part of that variable [1] can then be isolated using the syntax: LOCAL__Variable[1]@@

And that single chunk can be copied to the Clipboard.

EXAMPLE Select All Text up until Next Blank Line.kmmacros (28.5 KB)

Click to Show Image

Oh, that's clever! It only works about half of the time in my files though - even when there are 3 or 4 blank lines between paragraphs. Is there an obvious fix for it? Thanks

Just in case its useful to see the text I'm working with:

Okay so, an additional search and replace can be added into the Macro to deal with blank spaces that are bigger than two lines. The modified Action is the one coloured purple.

EDIT - updated with the Regex @mrpasini provided in the following post.

EXAMPLE Select All Text up until Next Blank Line 3.00.kmmacros (28.6 KB)

To convert two or more newlines into your delimiters, this regex should do the trick (saving you one action):

1 Like

Great. I've updated the Example Macro in my post above.

An alternative that copies @Zabobon's idea of using ⇧⌘↓ to select everything below the cursor but uses a shell command (sed) to capture just the part until the next blank line:

Copy to End of Current Paragraph.kmmacros (3.2 KB)

Using sed cuts down on the number of steps, but I know a lot of people prefer to keep their macros "Keyboard Maestro-native."

The third and fifth steps could be added to @Zabobon's macro. The third deselects the text and puts the cursor back where it was. The fifth deletes the intermediate clipboard created in the second step—this keeps your Clipboard History a little cleaner.

1 Like