This is a great example of how Apple has improved the developer experience for OS X in Snow Leopard. Snow Leopard contains some new APIs for "bookmark" creation, which appears to be the new behind-the-scenes name for aliases. The following four lines of code create a functioning alias on Snow Leopard:
NSURL *src = [NSURL URLWithString:@"file:///Users/bjh/Desktop/temp.m"]; NSURL *dest = [NSURL URLWithString:@"file:///Users/bjh/Desktop/myalias"]; NSData *bookmarkData = [src bookmarkDataWithOptions:NSURLBookmarkCreationSuitableForBookmarkFile includingResourceValuesForKeys:nil relativeToURL:nil error:NULL]; [NSURL writeBookmarkData:bookmarkData toURL:dest options:0 error:NULL];
Isn't that about a billion times easier?
I'm not sure what the relativeToURL: parameter is for yet; comments are welcome.