Mac service to convert aliases to symlinks

Finder Alias files on Mac, while useful, have bloated to 5 MiB on a typical Mac. Crazy. As far as I can tell, the bloat is due to huge icon images being embedded into every alias file. Ok, maybe that makes an alias file self-contained, but I don’t want hundreds or thousands of 5 MiB files all containing copies of the same icons. You would think that [at least for aliases to files without custom icons] the Finder would simply consult its own desktop icon database when required, instead of carrying the huge overhead of the icons in every alias file. If I move an alias file to a different Mac that does not have any files of the same kind, ok, just give me a generic document icon! Perhaps there’s some subtlety of Finder engineering that I’m missing. Anyway, I’m tired of the bloat.

Assuming that your files are stationary, instead of a Finder alias you can use a UNIX-ish facility called a symbolic link (symlink). In the process of whipping up an Applescript to make these, I discovered a decade-old Mac OS X Hints post entitled “A script to convert aliases to symlinks” that provides a shell script to do it: You pass one or more filenames of alias files as arguments; the script converts each alias file to a symlink. The Finder then subsequently treats symlinks as you would expect: A symlink behaves like an alias (and displays an icon badge like an alias).

I zipped-up the shell script: alias2ln.

Shell scripts are really only useful if you know how to obtain a command-line prompt, you know roughly what /bin/sh means, and you know how to set your path. Most Mac users don’t know these things. So, I packaged the shell script up into an Automator action: Alias to symlink.workflow. Unzip it. When you double-click, it will offer to install itself (into ~/Library/Services, as it turns out).

Once it’s installed, select one or more alias files, then choose Finder > Services > Alias to symlink. Watch the reference go from 5 MiB to a hundred bytes or so.

One thing you have to know: A Mac alias incorporates a mechanism to “follow” a file even if it is moved. A symlink has no such feature; when created, a symlink references a certain path fixed. (In fact, that path is precisely and exactly what the symlink file contains, along with one bit [in the inode, if you must know] that distinguishes it from an ordinary file.) If you move the original file, the symlink won’t function (unless you put some file or other into the original location).

On a closely related topic, Nick Zitzmann has created a Service, SymbolicLinker. Once you install this, select a file, then access the service through the Finder’s Services menu or through the Finder’s contextual menu. A symlink to the selected file[s] will be made and placed into the same folder. You can then move the [absolute] symlink anywhere you like. I have used the Keyboard preferences panel to make a keyboard shortcut key ⌘L for this service – that is, I have replaced the built-in “Make Alias” shortcut with a “Make Symlink” shortcut, so when I want to make a symlink, I just hit Command‑L.