6

I'm trying to add a folder with icon in Finder sidebar using code.

CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:path];
IconRef iconRef;
FSRef fref;

CFURLRef iconURLRef = (__bridge CFURLRef)[NSURL fileURLWithPath:@"/pathTo/icon.icns"];
CFURLGetFSRef(iconURLRef, &fref);
RegisterIconRefFromFSRef('SSBL', 'ssic', &fref, &iconRef);

// Create a reference to the shared file list.
LSSharedFileListRef favoriteItems = LSSharedFileListCreate(NULL,
                                                           kLSSharedFileListFavoriteItems, NULL);
if (favoriteItems) {
    //Insert an item to the list.
    LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(favoriteItems,
                                                                 kLSSharedFileListItemBeforeFirst, NULL, iconRef,
                                                                 url, NULL, NULL);
    if (item){
        CFRelease(item);
    }
}

CFRelease(favoriteItems);

But a warning shows up: CFURLGetFSRef is deprecated: first deprecated in OS X 10.9
So What's the substitute?

kilik52
  • 664
  • 1
  • 6
  • 13
  • 1
    Hi, Had the same issue when resolving alias'. I found this: http://stackoverflow.com/questions/21244781/what-replaces-the-now-deprecated-carbon-file-fsresolvealiasfile-in-python-on-osx Although the first answer is marked as -1 it still helped! Not sure if it's an actual answer for your specific situation, hence the comment here. – Todd Feb 07 '14 at 11:32

0 Answers0