有些应用程序(如DropBox)在Finder侧边栏中有自己的图标。其他一些应用程序也做到了这一点。我找到了将文件夹放在Finder收藏夹中的方法,但无法更改默认图标。
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);
没有错误。检查10.7和10.8
使用[[NSWorkspace sharedWorkspace] setIcon:folderIcon forFile:lPath options:0];