Extracting text from clipboard and doing something with it for all the tags


I need to adapt an existing macro that cuts a text with tags and then extracts text between the tags.
There may be several tags. They all contain different text.
The text must be filled in different fields in the target application depending on the tag.

I am at a loss because I had the original macro done for me, but the author is not available to me anymore to do the adaptation. It is too much for me, I used to do some scripting but now I am out of my depth.

The Action Items were supposed to show me what the text was and if the matching was correct.
These should be adapted to "Switch to TextEdit",

The text would be something like:

I would like to thank you for kind understanding of the situation.

Then I'd need it to do the following:

    • Cut all to Clipboard.
    • Switch to an application e.g. TextEdit for the sake of simplicity
    • If is in the clipboard, type "SJ" then press "Enter" then paste "I would like to"
    • If is in the clipboard, type "ASM" then press "Enter" then paste "kind understanding"
    • then repeat that for each of the tags. Each Tag has an associated action, like SJ, OBJ etc. Then the text under that tag needs to be pasted.

Cut Text to Tomedo copy Macro (v9.0.5)

Cut Text to Tomedo copy.kmmacros (14 KB)

Whilst you have given a very detailed explanation, please can you also give say
4 lines of input text and
4-8 lines of the expected output text.

I am not clear what you mean by Tag in this context.

While editing I deleted my sample, sorry
Input text:

The patient complains about pain in the neck.

There is a pin that causes the pain.

The pin should be removed.

Remove the pin and the pain should disappear.


SJ REM (presses Enter here)
The patient complains about pain in the neck.

There is a pin that causes the pain.

The pin should be removed.

Remove the pin and the pain should disappear.

If you have an existing macro you would like modified, it would help a great deal if you could upload the actual macro to the forum so we could edit that instead of trying to recreate it from scratch. If you're not sure how to do that, instructions can be found here:


1: I am assuming that each "section", could be many lines until there is another "section

There is a pin that causes the pain.
There is a pin that causes the pain.
There is a pin that causes the pain.
There is a pin that causes the pain.
<next section>

2: and are we talking in the "text" section
plain text only
enhanced text

Done, thanks for the tip

Yes, the text can have several lines, but the Regex takes care of that. The formatting is irrelevant for this use case.

Thanks, that was a big help. To be honest, I'm still somewhat unclear on what exactly it is you want this macro to do, but my understanding is that you want it to tab between fields, type text corresponding to the original tag, then paste the text that proceeded the original tag before tabbing to the next field and repeating the process. If that's correct, this modified macro should do the trick, and all you should need to do is change the app from TextEdit to the one you have in mind:

Cut Text to Tomedo 1.1.kmmacros (8.4 KB)

Hi there, and thanks a lot! I think the modification goes in the right direction.

It's kind of hard to explain, but I'll try:

I have a data source (a virtual machine) where I collect text.
I have a target application (an Electronic Health Records system). Because the EHR is a pain to use, I want to collect some text that is typed or dictated between the Tags (like ). The the text is collected by the macro and pasted to the corresponding fields in the EHR.

If I have an input like:

The patient complains about pain in the neck.

There is a pin that causes the pain.

The pin should be removed.

Remove the pin and the pain should disappear.

I need the following to happen:
Anything that comes after <subjective> but before the next tag gets stored in a variable (e.g. Subjective). Anything that comes after <objective>, should get stored to the corresponding variable (Objective).
If there is no text after the tag (e.g. <assessment>), then the variable should not be created.

After the macro has collected all the variables, it should switch to the target application (EHR).

In the target application, it presses Cmd-K, and then it needs to create an entry for the corresponding fields.
e.g. If there is text associated with a variable "assessment", it should type the code for that field (say: ASS) and then press enter, then paste the text of the variable, then close the field (which I can script).
Then, if there is text in the variable "Subjective", it should typ SJ (the REM was meant as Remark, as in Batch Scripting), then Enter, then paste the text associated with that variable and so forth.

It should then through all the variables and create the entries in the fields of the EHR if the variable has text.

Is this clearer now?

The use case is here is extremely specific and it's really hard to describe in a way that is clear.
I am willing to pay for someone to help me, maybe by showing them remotely what I need done. But offering money on this forum usually results in people telling them "to show what they've got". That's why I haven't it done yet.

Yes, that's a little clearer now, thanks. Based on that description, I honestly think the modified macro I posted before came pretty close. You didn't mention before that you want the macro to do nothing for tags with no proceeding text, but that wasn't too difficult to add:

Cut Text to Tomedo 1.2.kmmacros (10.3 KB)

I also added the K command to create a new entry field, so at this point, I think all you should need to do is change "Activate TextEdit" to this EHR app, and add the command needed to close each field after the tag and associated text has been entered. Try making those modifications yourself and seeing if this macro doesn't do what you want. If something still isn't working right, try listing the exact steps/actions you would take to perform this task manually (i.e. don't just say "create an entry" or "close the field," but write exactly what shortcut or menu command you would use to do that) and indicate which parts the macro is performing correctly and which it isn't. If you think it would be easier to show rather than describe, you could always record your screen, narrating if necessary, and post a video of that.

Hi there

Thank you so much!
I have a question: Does the script work for you with the sample text?

In my case nothing happens after switching to TextEdit. No error message, nothing.
I disabled Cmd-K, just in case, but still nothing.
Is there a way to debug?

Yes, it works fine for me:

You can debug why it's not working for you by first trying Interactive Help from the KM Help menu, or by turning on the Macro Debugger from the "Start Debugging" command in the KM status menu.

It works from TextEdit to TextEdit, but not from Word to TextEdit.
EDIT: it works from Word now that I have a Remove Styles filter. Apparently the macro hangs itself on formatted text.
It works for my VM, though, which is most important.

Your help is invaluable, thank you very much!