6

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

John Topley
  • 113,588
  • 46
  • 195
  • 237
Ankoma
  • 127
  • 1
  • 4
  • EDIT ONE : it works on 10.5 and 10.6 - but icon appears just after I click on it. I've found that here /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ stored all icons for toolbar like ToolbarDocumentsIcon and so on - but there is no DropBox icon for toolbar - how they did that ? – Ankoma Feb 25 '13 at 12:15

1 Answers1

0

use [[NSWorkspace sharedWorkspace] setIcon:folderIcon forFile:lPath options:0];

Parag Bafna
  • 22,812
  • 8
  • 71
  • 144
  • 2
    No there is another icon for finder Fovorites - Music, Documents, etc - folder looks like normal folder but in Favorites it has completely different icon. – Ankoma Feb 25 '13 at 11:39
  • 1
    10.7 and 10.8 - no results 10.5 and 10.6 it works but really strange - icon appears just after I click on it – Ankoma Feb 25 '13 at 12:11
  • first set icon for folder then add folder to finder sidebar.(this will work for 10.5 and 10.6) – Parag Bafna Feb 25 '13 at 12:14
  • 1
    not working - my folder has custom icon but in Sidebar it's appears just like normal folder – Ankoma Feb 25 '13 at 12:17
  • 1
    for 10.7 and 10.8 you need to inject code into finder.[rentzsch / mach_star](https://github.com/rentzsch/mach_star) **NOTE**:If you are submitting you app on app store dont use code injection. – Parag Bafna Feb 25 '13 at 12:20
  • 1
    Take a look at [How to Write OS X Finder plugin](http://stackoverflow.com/questions/1294335/how-to-write-os-x-finder-plugin) – Parag Bafna Feb 25 '13 at 12:23
  • 2
    It's no the answer. This is not Finder icon. Is there a solution withot common links to Finder plugins development? – Dmitry Mar 29 '13 at 11:19