以编程方式将文件夹添加到“地方"在Finder中 [英] Programmatically add a folder to "Places" in Finder

查看:94
本文介绍了以编程方式将文件夹添加到“地方"在Finder中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试弄清楚如何以编程方式将文件夹添加到Finder的位置侧边栏中.我已经看到了通过Finder首选项进行修改的方法,但是我也看到了一些应用程序实际上在侧边栏中添加了文件夹.

I'm trying to figure out how to programatically add a folder to Finder's Places sidebar. I've seen ways to modify it through the Finder Preferences, but I've also seen some applications actually add folders to the sidebar.

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

If someone has any advice/pointers on what I should look up, it would be greatly appreciated

(这是给Snow Leopard和Leopard的,希望它没有改变)

(This is for Snow Leopard and Leopard... hopefully it didn't change)

推荐答案

尝试一下:

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

这篇关于以编程方式将文件夹添加到“地方"在Finder中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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