1

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?

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 Answers1

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