Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Getting the contents of a textClipping file

My goal is to try to convert a folder full of textClipping files into text files. I've been able to get at the ".textClipping" finder items, but I haven't been able to get at the actual text of the textClipping finder item, not to mention taking each finder item and converting it into a text file.

Is this an appropriate job for automator?

I would normally just bring up a terminal window and write a shell script to convert these .textClipping files to text files, but I can't seem to get at the actual text of these files from the shell. The actual text seems to only be available to finder.

Anyone have any suggestions for converting these textClipping clipboard items into text files automatically without having to manually open each textClipping file and past it into a new text file individually for each textClipping file?

Message was edited by: kae to fix some typos

Most Mac's are running 10.4.11, but I have one with 10.5.2, Mac OS X (10.4.11)

Posted on Mar 17, 2008 10:44 AM

Reply
Question marked as Best reply

Posted on Mar 17, 2008 12:50 PM

While this may be a job for automator, I've done this in the past with a shell script. To begin, textClipping files store everything that you want in the resource fork. So if you break out terminal and you have a file named text.textClipping, use these variants to inspect the file.

ls -l text.textClipping
-rw-r--r--@ 1 user staff 0 Mar 17 14:32 text.textClipping
ls -l text.textClipping/rsrc
-rw-r--r-- 1 user staff 1323 Mar 17 14:32 text.textClipping/rsrc
ls -l text.textClipping/..namedfork/rsrc
-rw-r--r-- 1 user staff 1323 Mar 17 14:32 text.textClipping/..namedfork/rsrc

Note that the first output shows a 0 k file. That is because there is nothing in the data fork. Use the rsrc or the ..namedfork/rsrc addendum to find the actual data.

Now that we see there is some data there, you can use something like strings to see the contents:

strings text.textClipping/rsrc

But there is still too much information to parse through. So, you need a little bit of trickery and some unix skill. Warning, one size does not fit all. If you have textClippings that contain special characters, custom line breaks, or that are just real long, this falls apart fast. However, this is a starting point to get you on your way.

Use DeRez. This will require the installation of XCode tools and it can be found in /usr/bin/ man DeRez for all the details. However, you should be able to use it to extract the TEXT resource from the fork. A simple:

DeRez -only TEXT text.textClipping

will give you the exact resource you are looking for. But, you will also get all the extra garbage that you don't want. So the next big step is filtering. Use the following to help filter the result:

DeRez -only TEXT text.textClipping | grep '/\* .* *\/' | sed 's/^. / //;s/ \*\/$//' | tr -d '\n'

(hopefully the forum does not mangle that) This will take the output of DeRez, send it to grep to grab what is between the /* and */ characters and then takes those away and then removes newlines.

A mentioned, I used to have some trouble where I would get a tr: Illegal byte sequence error on certain clippings that were very long. I never fixed it or found a solution for it.

If you are bringing this into AppleScript or automator, make sure you add the extra escape characters.

Hope this is a good start.
4 replies

There are no replies.

Getting the contents of a textClipping file

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.