Strip Alias
Why are Mac OS X aliases so large? They’re huge! I’ve seen sizes from 1MB to 5MB for a single alias file. Back in the System 7 days, they were mere bytes in size. Their functionality hasn’t significantly 1 changed since then.
I poked around an alias file (with the help of xattr
, DeRez
, and GetFileInfo
) and found the answer: they’re storing icons in there now.
Twice. Once in the data fork of the file and then once in the resource fork of the file.
What? Why? To make it look pretty, of course. Well, to be fair, it’s so that the alias retains its appearance if you used a custom icon on the original or if the source application is no longer available. But still, 5MB for a file reference to what could be a 10KB file? Insanity.
So I tapped my memory for what made an old-school alias. It was a simple ‘alis’ resource back in the day. Sure enough, DeRez
said that was still in there. With some trial-and-error at copying all the old-school HFS attributes I managed to find a way to take an existing obese alias and thin out all the stuff that doesn’t make it an alias file. Then I made it a script that takes makes a copy of the original with all the crap stripped out 2.
The result? A file that goes from 5MB to 700 bytes. Bytes. It still works, even grabbing files in subfolders on network shares. (Well, the ‘alis’ resource is still there, of course!)
Lion introduced “bookmark” data to them which does give them more robustness when the originals move around, but that’s about it. ↩︎
It works on a copy of the file because that’s the state of the script when I finally got it working. As I have other things to do, that’s where I stopped. If you want to replace the original just chain a
mv
afterwards (e.g.,./strip_alias.sh alias alias-new; mv alias-new alias
). You are free to fork the gist and improve it now that the hard part has been done. ↩︎