开发者

Programmatically add a folder to "Places" in Finder

开发者 https://www.devze.com 2023-01-11 23:40 出处:网络
I\'m trying to figure out how to programatically add a f开发者_JAVA技巧older to Finder\'s Places sidebar. I\'ve seen ways to modify it through the Finder Preferences, but I\'ve also seen some applicat

I'm trying to figure out how to programatically add a f开发者_JAVA技巧older 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

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


Try this:

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

精彩评论

暂无评论...
验证码 换一张
取 消