简体   繁体   English

更改文件夹的Finder侧栏图标

[英]Change Finder sidebar icon for folder

There are some apps like DropBox that have their own icons in the Finder sidebar. 有一些像DropBox这样的应用程序在Finder侧边栏中有自己的图标。 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. 我找到了将文件夹放在Finder收藏夹中的方法,但我无法更改默认图标。

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 检查10.7和10.8

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM