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

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

3 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

As of yesterday, something very interesting happened.

I did not notice anything that I've done that could influence this behavior, but basically if there is an eligible https://. link, the macro does not work anymore, it works as it should with anything else as it always did.

So this will work correctly:

https://youtube.e
https://wikipedia.a
https://google.d

However this won't (nor with 2 or more characters after the second dot):

https://youtube.edddddd
https://wikipedia.addadfas
https://google.dasdfasdf

Say I try to sequential paste two times, the clipboard will be updated to (and there will be no original result):

https://youtube.edddddd
https://wikipedia.addadfas
https://google.dasdfasdf
https://youtube.edddddd
https://youtube.edddddd

I tried changing the keybinds, re-enabling the macros, re-installing the macro, restarting KM.

If I exclude the https (I've tried everything, it only fails to work with http:// or https://, so ttps:// doesn't work for example, nor attps://. I guess it has something to do with resolving, but how is that even possible?

I think it might have something to do with the hyperlinks being generated as the text is pasted.

The original Macro works by seeing the text as lines separated by line breaks. It seems that when pasting text that can be seen as a hyperlink address the app being pasted into automatically adds hyperlinks which messes with line breaks, tripping the Macro up. I don't really have an idea how you can deal with that (with the current Macro) as the hyperlinks get added by the App you are pasting into and have the effect of altering the clipboard. I will have a think. Maybe others on the Forum can come up with a solution.

1 Like

...except you aren't pushing back to the clipboard in your macro, yet the just-pasted item is, somehow, being appended to the clipboard rather than being removed! Strange indeed...

@optimizard -- What apps are you copying from and pasting into? Are you running any other utilities (clipboard managers, Better Touch Tool, Text Expander...) that might mess with the System Clipboard? Can you check your KM Engine log file (in the Editor, Help->Open Logs Folder then open Engine.log) to see if any other macro is triggering at the same time?

1 Like

@Zabobon @Nige_S

fixed the issue, it was with Velja, the option to remove tracking params when copying links was selected and it caused the issue.