Process text that is on the clipboard

Is it possible to have a KM macro that can process text that I copy to the clipboard before I paste it?

I have emails where I want to copy two lines of text and then paste them into a spreadsheet, but when I select the cell in my spreadsheet and paste, it overwrites data in the cell below it with the second line in my clipboard even though that cell is not selected. I would like the second line to go in the cell to the right of it rather than below it.

I think what I need is a macro that can take the text that’s on the clipboard (perhaps using variables) and simply change the line break to a tab before I paste it in my spreadsheet. Even a soft return would be better than the hard break so at least it doesn’t overwrite the cell below when I paste.

If something like this is possible with KM, can someone please help me figure out how to do it? Or tell me if it’s impossible and I’ll use a macro idea that I know will be slow and clunky but should at least get the job done.

Thank you!

You can use the Search and Replace Clipboard Action.
Search for \n and replace with \t
And then add a paste action.

Perhaps set the trigger to alt+cmd+v.

Like this:
Keyboard Maestro “Paste 2 lines to cells” Macro

Paste 2 lines to cells.kmmacros (1.9 KB)

1 Like

THANK YOU, @JimmyHartington!!! I was hoping there was something simple but I sure couldn’t find it. I did actually see this action, but for some strange reason I got it into my head that it was only for searching if a string exists in the clipboard so I ignored it. I hope I learned my lesson there.

Again, many thanks!

You are welcome.
I forgot to mention but you have probably figured it out.
\n is a newline
\t is a tab

This forum has helped me many times. So I try to help when time allows it.

1 Like

Hey @veramilo,

Always tell us what software you’re working with, as it can make an enormous difference in the solutions available.

In Microsoft Excel a carriage-return is considered a soft-line-break and a linefeed is a hard-line-break.

So you can do the appropriate conversions and paste, OR better yet you can directly insert text into the active (or any specific) cell.

set textToInsert to "Line 1\rLine 2"

tell application "Microsoft Excel"
   tell active cell
      set value to textToInsert
   end tell
end tell

** The \r above will compile in an Execute an AppleScript action to a CR character.

-Chris

1 Like

The earlier answer did precisely what I was looking for – modifying the contents of the clipboard itself – but I very much appreciate the reply. Thank you!