Finding specific text style in RTF data, then remove all styles


I am still fiddling with my flashcards.

I want to be able to enter a string and highlight certain parts of it in, e.g. by using a bold text style on these parts:

“This is not important, but this is.”

By bold text will then be manipulated further.

As I can see, KM has no macro or action to determine the text style of a string or part of it.

Therefore, I copy the styled text to the clipboard and convert the whole text including the RTF-metadata to sth. more readable, by using the output of:

osascript -e ‘the clipboard as «class RTF »’ |
perl -ne ‘print chr foreach unpack(“C*”,pack(“H*”,substr($_,11,-3)))’

(idea by a nice fellow in this thread:

With a regex that finds where bold text begins or ends, if any, I can then save the highlighted text an proceed as I wish with it.

However, I have to clean all the text then of all other RTF metadata, which is now in clear text. Thus copying the styled text to a plain text clipboard would not work.

Do I really have to search and replace all possible RTF data I am not interested in? Am I on the right track? Thanks for any input!

Hi Ben

Not sure how to do it, but could Markdown be used?

1 Like

Jimmy, a kind of markdown or markup would be my third best option. My goal is to have a human readable text with as few (distracting) meta information as possible.

This applescript seems to work for TextEdit at least (a Google find).

tell application "TextEdit"
     set boldText to attribute runs of text of document 1 whose font contains "Bold"
end tell
return boldText

some bold text is here -> {“is here”}

1 Like