Search code examples
cocoafinder

How to programmatically read Mac .textClipping files?


Those files are created whenever you drag a text selection to the Finder. The file size is always 0 bytes. Apparently the data is stored in a resource fork.

I tried reading the resource fork[1], but get error code -39 (end of file).

Here some more details about the file:

$>xattr  test.textClipping 
com.apple.FinderInfo
com.apple.ResourceFork

[1] http://www.cocoadev.com/index.pl?UsingResourceForks


Solution

  • Look up FSOpenFork and FSReadFork. (Apple has a code sample called AudioCDSample).

    There'a also a command line tool that can read those files (/usr/bin/DeRez), you may want to look at it under GDB, but from what I've seen it uses deprecated APIs (i.e. FSRead in place of FSReadFork).