views:

158

answers:

2

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
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
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
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
That is why I asked about Finder aliases.
kiamlaluno
+2  A: 

Nathan Day has a class here: http://homepage.mac.com/nathan_day/pages/source.xml#ndalias.

Dewayne Christensen
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
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
The code created from Nathan Day is available also on Git: http://github.com/nathanday/ndalias.
kiamlaluno
@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
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
Argh, <a href...> tag. Why doesn't SO treat HTML in comments the same as in answers?
Dewayne Christensen