以编程方式将文件夹添加到Finder中的"位置"

mys*_*tro 4 macos finder

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

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

(这是针对雪豹和豹子......希望它没有改变)

小智 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);
}
Run Code Online (Sandbox Code Playgroud)

  • 如何在沙盒中做到这一点?上面失败了,只有黑客直接写入该文件夹对我有用:D (3认同)