4

我试图弄清楚如何以编程方式将文件夹添加到 Finder 的 Places 侧边栏。我已经看到通过 Finder Preferences 修改它的方法,但我也看到一些应用程序实际上将文件夹添加到侧边栏。

如果有人对我应该查找的内容有任何建议/指示,将不胜感激

(这是给雪豹和豹子的……希望它没有改变)

4

1 回答 1

11

尝试这个:

-(void) addPathToSharedItem:(NSString *)path
{
    CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:path]; 

    // 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,
                                                                     kLSSharedFileListItemLast, NULL, NULL,
                                                                     url, NULL, NULL);
        if (item){
            CFRelease(item);
        }
    }   

    CFRelease(favoriteItems);
}
于 2011-10-09T23:07:22.973 回答