Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically add a folder to "Places" in Finder

Tags:

macos

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

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

like image 876
mystro Avatar asked Dec 22 '22 00:12

mystro


1 Answers

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);
}
like image 149
mself Avatar answered Jan 20 '23 13:01

mself