更改文件夹的Finder侧边栏图标 [英] Change Finder sidebar icon for folder

查看:287
本文介绍了更改文件夹的Finder侧边栏图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DropBox之类的某些应用程序在Finder侧边栏中有其自己的图标.其他一些应用程序也这样做.我已经找到了将文件夹放置在Finder收藏夹中的方法,但是我无法更改默认图标.

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);

没有错误.选中了10.7和10.8

There are no errors. Checked on 10.7 and 10.8

推荐答案

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

这篇关于更改文件夹的Finder侧边栏图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆