Change Finder sidebar icon for folder

ぐ巨炮叔叔 提交于 2019-11-30 15:48:08

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/15003407/change-finder-sidebar-icon-for-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!