Is there any way to programmatically read a textClipping file?

I'm trying to create a feature for my app that will import and parse textClipping files. Is there any way to actually do this?

Replies

I'm not aware of any API support for it. If a text clipping file is dragged to your app icon, I think you'll get an "open contents" ('ocon' a.k.a. kAEOpenContents) Apple Event, which will carry the data directly (with no need to parse the file).


Otherwise, the file format appears to be a pretty straightforward binary property list, although that's presumably an implementation detail. It's a dictionary. One of the keys is "UTI-Data", whose value is another dictionary. In that dictionary, the keys are UTIs whose values are the data of the appropriate type. If you support styled/rich text, you'd probably looks for "public.rtf" first. Otherwise, you'd use "public.utf8-plain-text" or the like.

I'd take a quick look at QuickLook:

It's a plain text file. See what happens if you try to open a clipping file with TextEdit. That will give you a clue as to how to read the content.

It's not a plain text file.


Save a text clipping to the desktop. Rename the file from "whatever.textClipping" to "whatever.plist". Now open it in a good plist editor like BBEdit. It is pretty straightforward from there.