Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

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
Question marked as Best reply

Mar 17, 2008 12:50 PM in response to kae

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.

Mar 18, 2008 4:21 PM in response to kae

kae,

I've had success using ClipEdit in conjunction with an Automator workflow:

1) Create a destination folder for your soon-to-be converted text documents.

2) After downloading ClipEdit, create a test clipping and open it in ClipEdit. From the File menu select Export As > RTFD Text… When the Save dialog appears, click on the "Where:" menu and navigate to newly created destination folder. Select it and press Save. Do this step for the sole purpose of establishing the default save-to folder. When completed, open the destination folder and delete the saved test document.

3) In System Preferences > Keyboard & Mouse > Keyboard Shortcuts, create a new application shortcut for ClipEdit, Menu Title: "RTFD Text…" without the quotes (use the Option + Semicolon keys to create the ellipsis, not three periods); and for this example, Command + Option + R for the Keyboard Shortcut. Click the Add button and close both ClipEdit and System Preferences for the change to take effect.

4) Create an Automator workflow using these actions:

a) *Get Folder Contents* -- From the Automator's Finder library

b) *Open Finder Items* -- Also from the Finder library. From the "Open with:" pop-up menu, locate and select ClipEdit.

c) *Run AppleScript* -- From Automator's Automator library. In System Preferences > Universal Access, make sure "Enable access for assistive devices" is checked. This code worked for me:

*on run {input, parameters}*
*tell application "ClipEdit" to activate*
*tell application "System Events"*
*tell process "ClipEdit"*
repeat
*if exists window 1 then*
*keystroke "r" using {command down, option down}*
*delay 1*
*click button "Save" of window "Export RTFD File"*
*keystroke "w" using command down*
else
*exit repeat*
*end if*
*end repeat*
*end tell*
*end tell*
*return input*
*end run*

Copy the block of code and paste it into the area provided inside the Run Applescript box, overwriting what's already populated there. Click on the hammer icon so that the script compiles.

Save the workflow as an application, to be used as a droplet, or as a Finder Plug-in, accessible in the Finder from a contextual menu.

The workflow is designed to work when the source folder contains text clippings only, and the destination folder is free of already converted duplicates of those yet to be converted -- either condition will stop the workflow dead in its tracks.

Just a thought... Good luck!

Andrew99

May 7, 2008 1:05 PM in response to kae

Thanks for the helpful suggestions. I tried both. I was more familiar with the first solution, but I want to learn more about the automator and applescript. I still don't understand these textClipping resource file types. That'll be something to learn more about. I have a UNIX background, so I still wonder where the data for these clips gets stored. There must be some kind of storage area that saves the Clipping data. I'll have to brush up on the Mac filesystem, but surely they don't store this in the inode area like UTS used to store the first 10k of data. Since the files show up as zero length and don't appear to have any special filesystem type associated with them, I'm just guessing that the data is stored somewhere else that has an index to the clip data.

Anyway, thanks for the help with this!

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.