Open text clipping files in TextEdit

Apr 01, '02 09:09:54AM

Contributed by: el bid

My first hint: very ugly, but offered here in the hope that something more beautiful will come of it.

MacOS X's Finder creates these rather strange .textClipping files when you drag text into one of its windows. As far as I can make out, only Finder can read them, either in its Inspector or in a Finder window that pops up when you click on the .textClipping file. I guess they're a legacy from Classic Mac, where presumably there are other apps that can read them (SimpleText?). You can't copy and paste their contents from Finder, so my task was to find a way of extracting their content into TextEdit.

Read the rest of the article for the workaround solution...

The trick is that the text is concealed (from normal MacOS X apps and command line utilities) in a resource fork. As well as the plain text, there's some binary junk in there too. So here's my quick and dirty command line fix. Open a Terminal and type:

 % cd directory/with/clipping/
% strings < Some.textClipping/rsrc > /tmp/xxx && open -e /tmp/xxx
Wow. This is ugly in at least a couple of ways. First, you shouldn't have to redirect the file into strings (the utility that strips out the binary junk); strings should just take the name of the file as a parameter. But Darwin strings complains that "it is not an object file". Duh!

The filename/rsrc hack to get to the resource fork has been discussed here before (thankfully, because that's how I learned about it). This in itself isn't ugly, although the use of resource forks in general and in this case in particular are, erm, somewhat... well, perhaps we'd better not get into that here.

Transferring the data through /tmp/xxx is a particularly nasty hack. I'd love to be able to do "open -e -", which would be the standard UNIX way of treating stdin (ie the data passed through the pipe) as the file to open. Alas Darwin open isn't written that way.

Well, there it is. I'd love someone to step forward and tell me it's all completely unnecessary because I've overlooked something!

Comments (15)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20020401090954295