Perl Script for Removing Mac Resource Fork

Perl Script for Removing Mac Resource Fork

perm url with updates: Perl Script for Removing Mac Resource Fork

Xah Lee, 2009-05-31

This page shows some perl script and tips for preparing Mac files to be used on Windows or Linux.

Resource Forks and File Type Code

Before Mac OS X, Mac files heavily relies on Resource fork. With OS X, it is decided in the early 2000s that resource fork is going the ways of dinosaur.

Another confusing thing is that Mac files often has file Type code. Its purpose is similar to Filename extension used by Windows and Internet media type for indicating which app can be used to open the file. The Type Code is not stored in Resource Fork, but is part of the HFS+ file system.

Resource fork for data files is discourage by Apple since early 2000s, and i think vast majority of modern apps does not create files with resource fork. However, Mac applications (those in “/Applications/” folder, may still rely on resource fork to function.

File type code are still used in OS X. However, it can be deleted without creating much problem, since all it does is associating files with applications, and this mechanism is largely replaced by filename extension.

For converting your old Mac files, you cannot simply delete resource fork, because for some files, such as “unflattened” QuickTime movie files, the main data is in the resource fork.

Here's a perl script that removes resource fork of image files. It can be easily modified to report files that contains resource fork. delete_image_file_resource_fork.pl. (resource forks in image files are almost always just thumbnails, created by application such as GraphicConverter. The thumbnail of image files created by Finder are not stored as resource forks.)

For some more details about how to use OS X's command line to check resource fork or file type, see: Mac OS X Command Line Tools Tips.

“.DS_Store” and “Thumbs.db” files

Mac also creates a .DS_Store file in each folder. ( Windows creates Thumbs.db) You'd want to remove them if you are copying them to Windows. You can run the following command in bash to remove them:

find . -name ".DS_Store"
find . -name ".DS_Store" -exec rm {} \; 

Here's a perl script that does the job in more flexible ways: delete_DS_Store.pl

“Icon^M” files

Another Mac specific file are those files named as “Icon^M”, where the “^M” is the Return character (ASCII 13). These are folder icon files, but am not sure they are necessarily in Apple Icon Image format. I'm not sure what's their official status with OS X. However, you can still find them in OS X. For example, you'll find it in “/Applications/Adobe Reader 8/”, as well in StuffIt 10, Mac Pov-Ray 3.6, Adium, and if you use Jamie Zawinski's XScreenSaver for OSX, you'll find a lot “Icon^M” files in your “~/Library/” dir.

Here's a perl script that delete these files: delete_macos9_icon_file.pl.

Popular posts from this blog

11 Years of Writing About Emacs

does md5 creates more randomness?

Google Code shutting down, future of ErgoEmacs