Update for 2015
The LSSharedFileList header says this has moved to the CoreServices framework. In fact, if you Cmd-Shift-O (in Xcode) and type LSSharedFileList, then navigate to the only result, you'll see in the jump bar that the header is indeed now contained within CoreServices.framework. In any case, the key is still kLSSharedFileListFavoriteItems.
Example:
+ (BOOL)appendFavoriteItemWithURL:(NSURL *)url {
// Pessimism ...
BOOL result = NO;
// Do we have a file URL?
if (url.isFileURL) {
// Ask CoreServices for the favorite items list
// (kLSSharedFileListFavoriteItems)
LSSharedFileListRef list = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteItems, NULL);
if (list) {
// We've got the list, so try to append our item
// (use kLSSharedFileListItemBeforeFirst vs.
// kLSSharedFileListItemLast if desired)
LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(list,
kLSSharedFileListItemLast,
NULL,
NULL,
(__bridge CFURLRef)url,
NULL,
NULL);
// Did it work?
if (item) {
// Release the item and flag success
CFRelease(item);
result = YES;
}
// Release the list
CFRelease(list);
}
}
return result;
}
Usage:
// Create the path to the favorite item to add
NSString * itemPath = [@"~/Music" stringByExpandingTildeInPath];
NSURL * itemURL = [NSURL fileURLWithPath:itemPath];
// Insert the item
[WhateverClassTheAboveFunctionIsIn appendFavoriteItemWithURL:itemURL];