开发者

How to programmatically access file resource forks on Snow Leopard?

I was recently wondering how Mac OS X stores thumbnails of files. After some Googling, I found out that about "resource forks", a feature apparently unique to Apple's HFS file systems.

I don't really like the idea of having resource forks around, and I would like to be able to delete them. Is there any way to access the resource forks programmatically? Various forum posts said that to see the resource fork of a file like presentation.pdf I sho开发者_开发技巧uld ls presentation.pdf/rsrc, but I haven't been able to find a file like that on my system. Is this still how it works in Snow Leopard?

I am not interested in downloading or buying some tool that does this for me. I'm comfortable with the command line, and ideally I would like a command line solution, so that I can script this.

And before I actually go through with this, I guess I should ask: is there any harm in deleting the resource forks?


It depends on what is in the resource fork. The use of resource forks has been discouraged, but there are few holdouts including alias files, custom icons (on files) and some legacy font files. You can verify if a file has a resource fork in the Terminal using "ls -l@". The resource forks are also exposed in the extended attribute APIs through the "com.apple.ResourceFork" attribute.

If you want to just remove thumbnails, you could do that from the Finder's GetInfo panel. The extended attribute APIs, like removexattr(2), will let you programmatically remove the Resource Fork.

If you're curious what's inside a resource fork you can use: "hexdump -C myfile/..namedfork/rsrc"

Hope this helps

-Don


You ask - "is there any harm in deleting the resource forks?"

Of course there is. Those are files that someone has constructed to be a certain way, and if you delete chunks from them, whatever program is using them is not going to be happy. You should only do so in certain situations where you know what you're getting into.

For example, Text Clippings (what you get when you drag a chunk of selected text to the desktop) are stored entirely in the resource fork. The data fork is empty. This is annoying, but it's the way it is. If you delete the resource fork, there goes all your text.

A better approach might be to contact the author of whatever software is still creating resource forks and try to convince them to abandon that practice, because you like having everything in data forks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜