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

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.

I actually have a question about the macro and an issue I've been fighting which slows down my workflow.

Whenever I paste multiple items, if perhaps I click too fast the macro bugs out and it skips that paste, or appends all the buffering remaining pastes instead, or just duplicates the paste.

My workflow for example is to grab hundred of links and paste them into my bookmark manager, since my bookmark manager (Anybox) doesn't support pasting multiple items all at once this is hacky way I go around that.

However if I do it too quickly there it can cause the issues that I've listed above.

I actually tried to fully automate the process, have this macro plus another that will just re-trigger this macro until completion instead of manually doing it myself, but since it usually bugs out if it's pasted too fast in between pastes, or sometimes it just happens even if there is a 2 sec wait for some reason, so I can't get it to work quickly enough in some programs without bugging out, thus I can't fully automate this sequential pasting while AFK

*Please just check the sequential paste repeat, not the issue I was having (that's resolved).

The original Macro was designed to paste lines from a multi-line clipboard one line at a time, when pressing the same hotkey. Each time you pressed the hot key and the Macro ran, it pasted the top line of the current clipboard and then resaved the clipboard with that line removed. So, the next time you pressed the hot key it would paste the next line in your list and so on.

But if you want to paste each line of the clipboard, one line at a time, as part of some automated task you could do that in a simpler Macro.

One thing to bear in mind is that each time the Mac Clipboard is used to either copy or paste, the current clipboard changes. So, before doing any pasting we need to convert the contents of the clipboard into a Variable (which will not change as the Macro runs).

  1. Take the contents of the multi-line text that is copied to the Clipboard and make that contents a Variable.
  2. Use a For Each Action to move through the lines one at a time doing whatever task you want to do each time.

To test this out with the example Macro below, copy some multi-line text to the Clipboard, such as

one
two
three
four
five

Then go to some text Application and run the Macro. Replace the green Placeholder Actions with whatever it is you need to acually do. If it trips up, you might need to add some pauses.

EXAMPLE Automated Sequential Paste of Lines in Clipboard Entry v1.00.kmmacros (19.8 KB)

2 Likes

Oh, this makes sense. Thanks.

I only added a pause after the second place holder text as the program tripped up if it didn't have that, now works fine.

Btw, say I copy 200 links into the application like, sometimes I might want to pre-emptively stop, what's the best way to stop this macro, should I add in the loop down below an until action with a keybind trigger?

There are many ways to stop macros.

Perhaps the simplest way is to simply click on the KM Engine icon in the system tray and select Cancel / Cancel all Macros. That will stop all your current macros. I recommend that everyone's first macros is a hotkey macro that runs the KM action called "Cancel all Macros," and if you did that, this would be a very effective solution.

Or you could add an IF statement inside your loop to cancel if it detects the user's desire to stop. Maybe something like this: (it will stop the loop if the user is holding down CTRL and OPT, but keep in mind that the test takes only a split second, and so the user may have to hold it down CTRL+OPT until the loop reaches that action. But this could be a safer way to stop, unlike the suggestions in the previous paragraph.)

image

2 Likes