What is the code necessary to create a Finder alias from a Cocoa application? Are there any differences between that code in Mac OS 10.4, 10.5, and 10.6?
+1
A:
You want -[NSFileManager linkItemAtPath:toPath:error:]
. AFIK, it and its related methods are the preferred means across all versions.
TechZen
2009-12-18 14:07:20
Isn't an alias different from a link? I think I read that a Finder alias as some features that are not present in a link, which would make it preferable to links.
kiamlaluno
2009-12-18 14:26:33
Hard links (as the one created with the reported function) cannot be created on a volume that is different from the source one. A Finder alias in a mix between a soft link and a hard link, which means that a Finder alias would be valid even when the file is moved, and it is possible to set an alias on a different volume than the source volume.
kiamlaluno
2009-12-18 15:42:10
A hard link is *nothing* like an alias. Hard-linking a file puts it in two places or under two different names (or both) at once. It does not create a new file of either a special type (symbolic link) or with special contents (alias or bookmark).
Peter Hosey
2009-12-18 23:31:13
That is why I asked about Finder aliases.
kiamlaluno
2009-12-19 07:03:59
+2
A:
Nathan Day has a class here: http://homepage.mac.com/nathan_day/pages/source.xml#ndalias.
Dewayne Christensen
2009-12-18 15:22:44
The reported link doesn't work; I get an error about the account not existing or not being active anymore. I think that homepages on .Mac / MobileMe is not an active service anymore.
kiamlaluno
2009-12-18 15:37:04
I don't know. It's working just fine for me, and I'm clicking the link directly in the answer above. Does it work any better for you if you change the %5F to an underscore?
Dewayne Christensen
2009-12-18 15:46:14
The code created from Nathan Day is available also on Git: http://github.com/nathanday/ndalias.
kiamlaluno
2009-12-18 15:46:16
@Dewayne Christensen: You are right; if I replace the %5F with the underscore, the URL works. I thought Safari should not have problems with the URL as it was. Thanks for the help.
kiamlaluno
2009-12-18 15:49:37
I updated the link. It appears SO was subbing in the %5F, until I explicitly wrapped the URL in an <a href...> tag.
Dewayne Christensen
2009-12-18 15:57:36
Argh, <a href...> tag. Why doesn't SO treat HTML in comments the same as in answers?
Dewayne Christensen
2009-12-18 15:58:32