I want to add custom place to Finder Favorites sidebar using LSSharedFileList API as described here. But I need to add a custom icon to this item. The icon should be in the IconRef
type. I have not found a way to do it. Found only a mention of the fact that the need to use Icon Services. But how?
Asked
Active
Viewed 1,047 times
1

Community
- 1
- 1

ZeroDivisi0n
- 140
- 8
-
If you will set folder icon using [[NSWokspace sharedWorkspace] setIcon:someIcon forFile:someFile options:0]; that will appear in finder sidebar. – Parag Bafna Sep 05 '12 at 14:09
1 Answers
2
You can use this function of Scplugin.
static IconRef IconRefFromIconFileNoCache(CFStringRef file)
{
IconRef iconRef;
IconFamilyHandle iconFamily;
FSRef fileRef;
CFURLRef url;
Boolean ok;
url = CFURLCreateWithFileSystemPath(NULL,file,kCFURLPOSIXPathStyle,false);
if (!url)
return 0;
ok = CFURLGetFSRef(url,&fileRef);
CFRelease(url);
if (!ok)
return 0;
if (ReadIconFromFSRef(&fileRef, &iconFamily))
return nil;
iconRef = 0;
HLock((Handle)iconFamily);
GetIconRefFromIconFamilyPtr(*iconFamily,(**iconFamily).resourceSize,&iconRef);
DisposeHandle((Handle)iconFamily);
return iconRef;
}

Parag Bafna
- 22,812
- 8
- 71
- 144
-
If one happens to have an `NSURL*`, one can cast that as `CFURLRef` and pass it to `CFURLGetFSRef`. – JWWalker Sep 05 '12 at 18:48
-
1This works, but unfortunately not suitable for use with `LSSharedFileListInsertItemURL` on Mac OS X >= 10.7 – ZeroDivisi0n Oct 04 '12 at 17:05