Copy loads of paragraphs in a row to Copy em Paste

Hi there dear KM users,

I am looking for an app that does the following

loop #start of a loop
Find Next “.+” #which should find all text in one paragraph without the \n return
goto loop #start the loop again (and copy the next paragraph until the end of document)

This is the scenario:
I’ve got one file with 1000+ paragraphs

I want to copy each paragraph in this file, beginning with its first paragraph, so that every paragraph appears in its clip in Copy Em Paste.
At the end I would have 1000+ clips in CEP.

Many thanks for your help and best regards Matze

I think what you call a "paragraph" KM calls a "line", IOW, all text until a end of line is found.
So, you might try this:

  1. Read a File action (KM Wiki) into a KM Variable I'll call "sourceText"
  • For Each action (KM Wiki) on "sourceText" using a collection of "lines". Each line goes to Variable "lineText"
  • In the For Each Action block, use a Set Clipboard to Variable "lineText"
  • You may need a short Pause of 0.1 to 0.2

I think that should do it.

Hi JMichaelTX and thank you for your hints.
I have managed steps 1 and 2.
I then set Clipboard to Variable "lineText"
but don’t know where to set the Pause here .

I’d like to show you a screenshot, but I can not find any uploadbutton.

Here's the complete macro:

You don't need the last action -- it is just there so you can quickly see the results. You can disable/delete this Action in your production macro.


###How To Upload Your Macro

If you have not been through the Getting Started process, then you should do so now. It will greatly help you.

###Getting Started with Keyboard Maestro

  • Read the Quick Start.
    • This is essential to become familiar with KM terminology
  • Do the tutorial (Help ➤ Tutorial) in the KM Editor.
    • Gives you a live walkthrough of creating a macro in the KM Editor
  • Review/Browse the Available Macro Actions
  • For Help with an Action in your Macro, click on the gear icon at the top right of the Action, and select "Help"
  • Search the Keyboard Maestro Wiki for detailed help.
  • Start small, and grow your macros organically.
  • Be prepared for some trial and error in the beginning.
  • Make good use of this Keyboard Maestro Forum
    • Search for existing macros
    • Post your questions/issues if you get stuck

Dear JMichaelTX,

too kind, thanks a lot!
I've activated the macro to copy nine lines in a sample file.
It resulted in three clips in Copy em paste:
\nisusselectcaret \par }}}
\lin2116 \fi-2116 \ri0 \rin0 }{\listlevel \levelnfc0 \levelnfcn0 \leveljcn0 \levelfollow0 \levelstartat1 \nisuslevelnuminc1 \levelspace0 \levelindent0 {\leveltext '12'00.'01.'02.'03.'04.'05.'06.'07.'08.;}{\levelnumbers '01'03'05'07'09'0b'0d'0f'11;}\li2336
\lin720 \fi-432 \ri0 \rin0 }{\listlevel \levelnfc4 \levelnfcn4 \leveljcn0 \levelfollow0 \levelstartat1 \nisuslevelnuminc1 \levelspace0 \levelindent0 {\leveltext '02'01.;}{\levelnumbers '01;}\li1080

In KM I got this window.

Since you didn’t actually state your issue/problem, I’m not clear as to what it is.

Please post your actual source text in a code block:
###How To Post Example Data

When you post example data, please put the data in a code block, between lines of triple backquotes:

– Your DATA Here


Welche ist die bevölkerungsreichste Stadt Mexikos?
Mexiko City (Stadt)
Welche ist die bevölkerungsreichste Stadt der Ukraine?
Welche ist die bevölkerungsreichste Stadt in Norwegen?

This is the sourceText.

This is the macro


Kopieren.kmmacros (3.2 KB)

It seems that the macro is copying whole paragraphs (\par)? So a line in KM is actually a paragraph ".+\n"? If so, how to prevent KM from copying the return as well?

The extraneous text like \par is occurring because you are using a rich text file for the source text. You could try using a regex to grab only the text you want before adding it to the clipboard, but a faster and easier solution may be to simply copy all of the text from the source RTF file and save it as a plain text file (or just add all the copied source text to the sourceText variable directly using KM's preferences or a Set Variable to Text action). However you convert the source from rich text to plain text, it should resolve your issue so that you get results more like this:

Thank you, Gabe, saving my file as .txt did it … nearly.

The Clipbard History Switcher shows all copied lines. But Copy em Paste only has got the first two clips.
Welche ist die bevölkerungsreichste Stadt in Norwegen?

I have set the Pause to 1 sec. and this did help. CEP is too slow :wink:

Thank you Michael and Gabe!

What specifically do you need them in Copy em Paste for? Is it something that Keyboard Maestro can help with instead?

Hi Peter,

I copy thousands of lines into Copy em Paste. And then I paste clip by clip into a flash database via Chrome.
Can KM do this?

I have purchased KM now, only this one macro Michael posted is worth the money.
Now I have to learn :wink:

Best and thanks again, Matze

Yes, easily.

But you may not need to put the lines on the Clipboard first.
You could just read the file, and put each line directly into Chrome.

Can share the URL where you have been pasting the lines?

Interesting, but unfortunately this database is not public.
But there is nothing special about it. Just fields, where you would paste
the lines.
It’s a quiz database, so one field for the question, one to three for answers, one for an explanation, source and so forth. Buttons to click to save etc.

If you’re doing it manually, then you can just use the Clipboard History Switcher in Keyboard Maestro.

If you want to automate it, then there are all sorts of possible ways, it depends on the exact sequence of clipboards and fields and how consistent it is. The “one to three” part will need some dealing with for example.

If you have more than a hundred (which is the default Keyboard Maestro limit on clipboard history), then you either should increase that limit, or more probably want to store the data somewhere else, rather than the clipboard history. Especially since Keyboard Maestro clipboard history does not include repeats, and it’s possible you could have two questions with the same answer (eg a number like “7” could answer two different questions).

Perhaps some screenshots of the source data and the web site would help.

Hi Peter,

here is my routine of pasting and clicking.
It is not possible to put all the questions in a row into the database, cause I have to check the clips again before saving.
But if these nine or eleven steps could be automated, it would be a timesaver.

Best, Matze

Source data is a plain text document with thousands of paragraphs of text, I have written in Nisus Writer Pro.
What is the name of our planet?
(Also known as the blue planet)

Controlling that should be relatively straight forward. At the worst you could just use clicks relative to the window. Better would be clicks relative to found images in the window, and better still would be to use the web browser actions to click the links or adjust the checkboxes or what have you. It depends on the web page though, and how well behaved it is.

Given the web page is presumably very static, and you’re going to be doing all of this in a short time frame (so the web site wont change), just using UI actions related to clicking or pasting is probably straight forward. Just a sequence of clicks, pauses, typed text (for menu selection) or pasting (for text input).

With the source data, how can you tell when the next question starts?

Reading the file line by line can be done using the For Each action and the Lines In collection. No clipboard is even needed for that.

Basically, you have a couple easy problems:

  • Copying each line of text from the file
  • Controlling the web page (probably).

And one tricky problem:

  • Figuring out which lines of your data go where, including figuring out when one question ends and one starts.

If you can resolve the latter, the rest will probably fall in to place.

Dear Peter,

me as a KM-newbie will keep your suggestions in mind for the time I might have learned how to use KM-basics. In 2018 this task will rise again and then I’ll give it a try… For now handling one question at time by pasting the clips into the database and clicking by hand will do.


Best Matze

In that case, might I suggest you just automate a small part of it.

The task must be pretty repetitive, so note down the exact sequence you do, even if for just one case (say when there is exactly four answers for example).

Note exactly what you do: Copy N things in order, then whatever sequence you do on the web page exactly.

Then create a macro that does exactly the same sequence (you can even use recording to record the click locations).

In your macro, it is best to start after you copied each of the N things, and set the clipboards into variables using the %PastClipboard% token. Then in your recorded macro template, add appropriate pauses, and use the Insert Text by Pasting action with %Variable% tokens.

But, of course, it’s entirely up to you as to whether that will make the overall process go faster.