Need to know translation from clipboard to rtf

Hello!

If of you knows the codes for bold and such, and whether it is represented for each character on the clipboard, of for a stream of characters until the formatting change, or, could give me a pointer to some doc on this, then I would be very happy :slight_smile:

What I need to know, restating it, is how styled text on the clipboard relates to rtf encoded text, if I may call it that. that.

All I really need to know is how to reckognize text in a document as bold, and encode the clipboard, consisting of a tag, to whatever combination of bold, italics and plain text is there, not considering (hopefully) font, or any other font-attributes.

Thanks!

Copy some styled text and run this:

set theDesk to path to desktop as text
set x to the clipboard as «class RTF »
set fileRef to (open for access file (theDesk & "Test.rtf") with write permission)
set eof fileRef to 0
write x to fileRef
close access fileRef
set theRTF to read file (theDesk & "Test.rtf")

And good luck parsing RTF…

Thanks, guys. This has turned into a really interesting topic. I’ve often wondered what dictates what the inline tags actually mean. I’m assuming it’s an internal Microsoft thing as you can have the “same” tag in two different sentences, but have a different effect.

I’m in the middle of something at the moment, but I’ll give that other script a shot later today.

I’ll report what I find back here.

Regards,

Bowjest

Thanks Shane!

I’m not going to parse RTF :slight_smile: , only figure out if it has a bold, italic, both, or no style tag. :slight_smile:

I’ll try your code, I am also to get the clipboard with styled text from script-debugger, and see if there are some kind of pattern in the data (style attributes) of the record.

@ bowjest This relates to this post so I need you to answer that one! :slight_smile:

No, it’s public. Not exactly light reading. And Apple has its own extensions to it.

Sounds like parsing to me.

At any rate, you’ll probably want to look for \b and \b0 plus \i and \i0, in all cases preceded by a linefeed and followed by a space.

Hello Shane!

I now believe I have a way to go with this, given the knowledge you were so kind to provide for me.

I now have deduced that the first part of the data, is kind of a common header, for the particular document at least, when coercing the clipboard to a record, as I have had something readable to reason from.

I have also deduced that the scrapstyles contains the styles I am interested in.

What I basically will do, is to make a paste and match style function, and see if it works. The “attribute run” seems to be of constant length, and not related to the number of chars copied from the document in the first place.

What I am after is a paste and match style, so I’ll use System Events to copy one character to the left of the insertion point, get it from the clipboard as a record, and set the text attributes in that record with new values, before I
coerce the record back to «class RTF » ( three chars :slight_smile: ) and puts it on the clipboard, and paste it back.

Then I have the correct “RTF header” and everything, I haven’t have the time to program it yet, I’ll come back with a solution, when I have it working.

Thank you very much for your help!