Text Factory and Multiply Styled Text

This is for Tinderbox, which uses the TextEdit text engine.

I have text that is already in there. It has two styles. The markup is smaller and grey while the marked text is dark red, almost black. A typical macro will have ten alternating zones.

(The markup is neither html or markdown, but it may be useful to think it were.)

I have the problem of curly quotes appearing. They appear in both styled areas.

The thing I want to accomplish is to straighten quotes and retain the style. At the moment, I copy to a named clipboard, apply a text factory and paste the result. The quotes are straight but the applied styles are gone. (The pasted result is all small grey.)

Is there an alternative strategy worth exploring?

I would be inclined to pipe an rtf version of the clipboard

pbpaste -Prefer rtf

through a textutil conversion from rtf to html

in which I would do a series of string replacements

‘ β†’  '
’ β†’  '
“ β†’  "
” β†’  "

before using textutil to convert back to rtf, and pbcopy -Prefer rtf to get a modified rich text version back into the clipboard.

PS this may get you started, formatting is retained. (In TextEdit the line width changes a bit, though not it the sample I tested in Tinderbox).

In Tinderbox you would just select the text and run this macro. (You may well find that you can remove the precautionary pause action)

Before and after, above and below:

Plain single and double quotes for selected RTF.kmmacros (3.0 KB)

Essentially a search and replace in an HTML version, then converting back to RTF:

osascript -e "the clipboard as Β«class RTF Β»" | perl -ne 'print chr foreach unpack("C*",pack("H*",substr($_,11,-3)))' | textutil -stdin -stdout -format rtf -convert html -encoding UTF-8 | sed -E 's/(β€œ|”|“|”)/"/g' | sed -E "s/(β€˜|’|‘|’)/'/g" | textutil -stdin -stdout -format html -convert rtf -encoding UTF-8 | pbcopy -Prefer rtf

( PS If you want a particular output line width, you could prepend a style string for <p> before the reconversion to RTF )

1 Like

UPDATE

In principle perhaps you should be able to do this in Keyboard Maestro with:

though in the example I tested it seemed to fix double but not single curlies.