I'm using Spotlight to index the UID and SpotlightFS to make access a simple matter of accessing a URL such as file:///byUID/o9e8 (making Spotlight an implementation detail that can change later). I can formulate a Spotlight query that'll return exactly one result — the one with the corresponding UID — but SpotlightFS will always give you a directory of symlinks whose names encode the true paths to results (link targets), meaning they vary based on the path. An example query (not using my UID stuff) with one result:
me$ ls -la /Volumes/SpotlightFS/SmarterFolder/exec_separate_vm/
.
..
:Users:me:JavaSnoop.properties -> /Users/me/JavaSnoop.properties
What I want is a predictable symlink that works when there's exactly one result, linking to that single result. The only way I can see to do this and keep file:///byUID/ URLs working is to patch SpotlightFS. The resulting patch (to version 2.0.3,2, ready to be dropped into /opt/local/var/macports/sources/rsync.macports.org/release/ports/fuse/spotlightfs/files/) allows me to do this:
me$ ls -la /Volumes/SpotlightFS/SmarterFolder/exec_separate_vm/the-only-result
/Volumes/SpotlightFS/SmarterFolder/exec_separate_vm/the-only-result
->
/Users/me/JavaSnoop.properties
It doesn't show up in the directory listing of a SmarterFolder query — if you don't stat() it, you'll never know it's there (which could be considered a feature). If there are zero results or multiple results, it'll provide the same symlink with an explanatory message as the target:
me$ ls -la /Volumes/SpotlightFS/SmarterFolder/arloegu098pgm/the-only-result
/Volumes/SpotlightFS/SmarterFolder/arloegu098pgm/the-only-result
->
error-there-must-be-exactly-one-result