AppleScript help: add HTML text-formatting tags to plain text pasted into a metadata field

Seeking help with an AppleScript intended to convert text in the clipboard. Let’s say the following formatted text is copied, somehow, to the clipboard:

Spengler, Egon. “Spores, molds and fungus.” Le journal du fromage bout à bout; Funkytown: 1234.

…I would like to take that string of baloney and paste it into a custom metadata field called “citation,” but when it pastes into there–I assume, as plain text–I’d like to retain the ability to convert that plain text back to its original formatting. So in other words, I presume the italicized part would be wedged between some code looking sort of like this <i> and this <i/>.

For this to really be useful though, a second AppleScript would then be required, I presume, to do the exact opposite; this one would facilitate the copy-and-paste of the plain-text contents in the metadata field, in such a way that the pasted text looks exactly like the formatted text, without the formatting codes showing.

…or maybe my logic or understanding of how this could work is a bit flawed, lol! Any guidance on this workflow/concept would be really appreciated. Thanks in advance!

I just wonder whether it might prove a little less challenging if you try working with annotations for your purpose:

(See the user guide (also available through the in-app Help).)


The macOS clipboard can simultaneously hold differing formats, and the one used for pasting can be chosen, behind the scenes, by the app we paste into.

For example, the clipboard could contain a plain text Markdown version, as well as an RTF or HTML version.

The former would be used if you paste into a plain text field/editor, and the latter when pasting to a rich text field/editor.

The starting point (does the clipboard contain HTML or RTF for example) depends on the somehow in your scenario:

(different editors/app will populate the clipboard with different sets of formats at the moment of copying)

A script, as you suggest, can update the clipboard contents, but to sketch such a script, we need to know where we are starting (which app are you copying from ?) and where we are going.

One approach might be to use a tool like, which can convert between many formats, from some kind of launcher like Keyboard Maestro which can access the keyboard and make use of scripts.

Maybe some of Brett Terpstra‘s markdown tools could be of some help. Especially the ones for converting in to / out of clipboard.

I’m glad you shared this, because I routinely forget about the Annotations inspector, and I know I could take advantage of this utility in various ways. (You’ve compelled me to delve into this more.) Thank you for this, Stephen!

For lurkers: Stephen’s screenshot is a clip from the Help documentation’s section for the Annotations inspector. A one-word search for Annotations within Help (documentation) will get you there.


What are you trying to do? Couldn’t you use custom meta data of type rich text ?

From help:

Rich Text: Same as Multi-line text but supports basic formatting, e.g., bold or italic text.

1 Like

This is such a succinct and easy to follow explanation. Thank you for laying all of this out!!

To get right to your question: the original source text will always be an RTF file in DT itself. In my case, these are source-citation templates of various types. The ultimate end-destination–by way of a custom metadatafield in the middle–is however an external app for genealogy, called Reunion, and this little bit is probably important: Reunion does accommodate formatted text to be pasted into what it calls a “Freeform” text box. So in other words, if I actually copied a citation with italics, bold and/or highlighted from the web, or a PDF or anywhere else, and pasted that text into the Create New Source “Freeform” text-box, the formatted text will indeed automatically render.

How it automatically renders though, I have no idea. Would it help us if I asked the software developers? Happy to do it if of use.

It occurs to me also that saying “HTML” in the title of my post is foolishly presumptuous. Maybe it’s another protocol instead. What I do know, for certain, is that genealogy databases still adhere to an old text file format, called GEDCOM, for exporting from one platform and importing into another. As they are simply text files, they’re actually viewable in TextEdit. I’ve done this before and remember seeing things like <i> before the beginning of an italicized word in a source citation, so therefore assumed the format was HTML.

This is outrageous. How did I miss this? :sweat_smile:

Edit: tested, works like a charm for my purposes. VERY HAPPY outcome! TY @pete31

1 Like