There are some apps like DropBox that have their own icons in the Finder sidebar. Some other apps did that too. I've found the way to place my folder in the Finder favorites, but I'm not able to change the default icon.
IconRef iconRef;
FSRef fref;
CFURLRef iconURLRef = (CFURLRef)[NSURL fileURLWithPath:@"icon"];
CFURLGetFSRef(iconURLRef, &fref);
RegisterIconRefFromFSRef('SSBL', 'ssic', &fref, &iconRef);
CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:path];
LSSharedFileListRef favoriteItems = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteItems, NULL);
if (favoriteItems) {
LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(favoriteItems, kLSSharedFileListItemBeforeFirst, NULL, iconRef, url, NULL, NULL);
if (item){
CFRelease(item);
}
}
CFRelease(favoriteItems);
There are no errors. Checked on 10.7 and 10.8
use [[NSWorkspace sharedWorkspace] setIcon:folderIcon forFile:lPath options:0];
来源:https://stackoverflow.com/questions/15003407/change-finder-sidebar-icon-for-folder