Separate each Line on System Clipboard onto it's own Clipboard

Is there a way to take a few lines of text like this:

Example line 1
Example line 2
Example line 3
Example line 4

Copy it to the clipboard and then trigger a macro that will copy each line to a seprate clipboard?

System Clipboard: Example line 1
1: Example line 2
2: Example line 3
3: Example line 4

Sorry if this is basic stuff, but I can't figure it out.

Depending what you want to do with the lines once they are split there are various ways you could go about this. Could you describe what you want to do with each line once they are split out?

Will there always be 4 lines or sometimes more or less than 4?

1 Like

I want each line to be copied to a the clipboard history. Here's the process:

  1. Copy all four (or however many) lines of text to system clipboard
  2. Trigger macro
  3. Each line is then copied to it's own clipboard, so they would be in the clipboard history.

I'm trying to set up sequential paste in the Paste Bot app without copying each line individually.

Okay. This will do that. (The magenta Action at the top would not be needed in real use as you will be copying the lines. And the last green display Action is only there to show the results.)

I added in a Filter Action to reverse the lines so the first line is the latest in the Clipboard History. If you do not want that you can delete the Filter Action.

After running this you will see the lines in the Clipboard History Switcher as separate past Clipboards.

It will work no matter how many lines there are.

EXAMPLE Split Lines in Clipboard into Separate Clipboard History Entries.kmmacros (4.6 KB)

Click to Show Image of Macro

2 Likes

Thank you, that is greatly appreciated. I am confused to find that this macro works exactly as intended, however, the pastebot clipboard does not reflect the changes, but the Keyboard Maestro clipboard does.

I will make a macro that serves the purpose of the sequential paste using Keyboard Maestro. That should be pretty straightforward.

Again, much appreciated

1 Like

It’s actually quite fiddly as when you paste a past clipboard using KM it becomes the current clipboard so, the order keeps changing…

Clipboard utilities don't always play nice with each other...

I would probably rate this as a bug and report it to the Pastebot people, but I would want to run some tests first. (It turns out that they have a demo.)

I have to slow down the copy to clipboard actions by fully 1/2 a second to get them to stick in Pastebot...


Download Macro(s): Coerce Pastebot to Accept Lines from Keyboard Maestro v1.00.kmmacros (5.8 KB)

Macro-Image

Keyboard Maestro Export

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 10.14.6
  • Keyboard Maestro v10.2

One small problem. It seems to filter out duplicate lines. Is there a way to write it so that it keeps the duplicates?

That is the way the Keyboard Maestro Clipboard History Switcher works.

I am thinking that if you just want to work with text, you should consider saving the lines to a Variable or Dictionary rather than past Clipboards.

What are you planning on doing with these "collected" lines? Your end goal might determine the best way of saving them, ready for use.

1 Like

The existing macro in this thread is perfect, I just need it to not remove duplicates because I am pasting data into an agenda and many of those fields are the same.

I'm going to paste the lines one by one into fields in WordPress. I have a second macro that pastes the top item in the clipboard and then deletes it.

Hi @stationagent - it’s not the saving macro that is removing the duplicates. That is what Keyboard Maestro’s Clipboard History does. And as you are using a Keyboard Maestro macro to paste past clipboards it will not allow duplicates.

Thanks @Zabobon.

So not perfect, then. Look at doing it something like this, assuming your first line goes into the first field etc. In pseudocode:

go to first field in web form
for each eachLine in variable
   set the system clipboard to contents of eachLine
   paste from system clipboard into active form field
   keystroke Tab
end for each

...mimicking what you'd do manually.

For more precision you could look at using Javascript to set the fields, by name or id, to the values you want.

I had another think about this. Instead of having two macros it would be simpler to just have a Paste Macro that pastes each line of a single multi-line Clipboard entry one line each time. In other words, no need to split the Clipboard entry into multiple past Clipboards or into Variables.

To use the below Macro, copy the multiple-lined selection to the Clipboard as you normally would by selecting all the lines in one go and pressing ⌘C

Then each time the below Macro is run it pastes one line from the copied text, working its way down the lines one each time. The good thing is that it will allow duplicate lines.

(The method to remove the first line of the Clipboard entry each time is by @Tom here.)

EXAMPLE Sequential Paste of Lines in Clipboard Entry v2.00.kmmacros (19.2 KB)

Click to Show Image of Macro

2 Likes

@Zabobon You did it. Thank you so much. This rocks.

1 Like

Another thing. If you leave the Keyboard Maestro History Switcher open (and make it as small as you can) the top entry will show what lines remain and you can see what line will be pasted next (a bit like Pastebot).

EDIT: I have updated my Macro in my post above to version 2.00 to clean up the past clipboards and make this display clearer.

EXAMPLE Sequential Paste of Lines in Clipboard Entry v2.00

2 Likes