Create self-updating symbolic links

Nov 10, '03 09:11:00AM

Contributed by: Morth

You can create symbolic links that update themselves when the target moves, just like aliases, but this only works with HFS+ volumes. This is done by targeting the symlink into /.vol/. The only problem is that if the target is deleted and then replaced (instead of just truncated), the symlink will stop working. To start, you need to know the /.vol/ path to symlink to, and you use the Terminal and the Finder for that. In the Terminal, type:

sudo fs_usage | grep 'getattrlist[^@]*Finder'
and then select the item you want to symlink to in Finder. Don't actually open the selected item, because the Finder will start to access stuff inside it (if it's a folder). When you select the item in the Finder, the Terminal window should now display at least one line like this (extra spacing deleted to save width):
15:45:08  getattrlist   /.vol/234881031/3053977   0.000051   Finder
The last one is your target, so you can create the symlink by typing:
ln -s /.vol/234881031/3053977 myalias
This link will stay the same even if you move or rename the target.

[robg adds: In my testing, I couldn't seem to figure out which of the several getattrlist items to select -- if I clicked a folder, for instance, I'd get about 20 lines of output, some of which were dupes, but others weren't. If anyone can clarify this method, I think it could be very useful.]

Comments (2)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20031102095712838