2

I have an application which has to be shown on Users list of Finder's sidebar on installation.

So on installation code, I have added one more dictionary object to Library -> Preferences-> com.apple.sidebarlists.plist.. i.e., in useritems -> customListItems of plist.

If I see the plist addition everything looks correct.

On relaunching the Finder.app, it is expected to get that item added in the side bar of Finder. But I am not able to see any change happening instead the plist is overridden with the old items. I tried trashing Finder cache and running the code. still no luck :( Any pointers to what I am missing please. Thanks in advance!

Liyali
  • 5,643
  • 2
  • 26
  • 40
Balaji
  • 21
  • 4
  • Try listening to ALL possible notifications in distributed notification center. Maybe finder gets some sort of notifications when item is being added/removed to/from the list. So after adding the entry into plist you should send the very same notification (if there is one). – Eimantas Aug 17 '11 at 10:42
  • Thanks Eimantas. I just tried catching all the notifications while adding sidebar item manually to Finder and also while adding item to plist. but in both cases i could not see any notification being sent. but when I try relaunching the Finder.app, a notification called com.apple.Finder.LaunchNotification is fired while restoring the sidebar. Not getting a clue. NOTE: am using Snow Leopard. – Balaji Aug 17 '11 at 11:43
  • Take a look at http://stackoverflow.com/questions/1062856/how-do-you-programmatically-put-folder-icons-on-the-finder-sidebar-given-that-y – Aeon Mar 25 '13 at 04:05

1 Answers1

2

Use LSSharedFileList. Add an item to the Finder/Save dialog sidebar

-(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);
}  
Aeon
  • 6,467
  • 5
  • 29
  • 31