Add Item to Finder Sidebar

I would like to add a new item in the sidebar Finder. I found out that the Finder stores the list of "places" in `~ / Library / Preferences / com.apple.sidebarlists.plist. I was able to read the file using the Carbon API and saw that each element has a name, icon and alias.

Using a third-party application such as PlistEdit Pro, I was able to update the alias. My question is how to update an alias using the Carbon API. Could not find a way to create an alias that opens in Finder. It seems that both Dropbox and PlistEditor Pro were able to find a way.


Edit: See updated answer for 2015

+6
cocoa carbon finder plist macos
source share
3 answers

Take a look here :

The file sharing list API is new to Launch Services on Mac OS X Leopard. This API provides access to several types of system-wide and for users permanent lists of the file system of objects, such as recent documents and applications, favorites and login Items. See the new LSSharedFileList.h interface file for more information.

You want to find the key kLSSharedFileListFavoriteItems, which processes the items in the Places section of the sidebar. I think you could try to do something similar to this using LSSharedFileListCreate to create kLSSharedFileListFavoriteItems.

Or you could use the published applescript here , which would be simpler but not the "Right Way" ©

+6
source share

Update for 2015

The LSSharedFileList header says it has moved into the scope of CoreServices . In fact, if you are Cmd-Shift-O (in Xcode) and enter LSSharedFileList, go to the only result, you will see in the transition bar that the header is indeed contained in CoreServices.framework . In any case, the key is still kLSSharedFileListFavoriteItems .

Example:

 + (BOOL)appendFavoriteItemWithURL:(NSURL *)url { // Pessimism ... BOOL result = NO; // Do we have a file URL? if (url.isFileURL) { // Ask CoreServices for the favorite items list // (kLSSharedFileListFavoriteItems) LSSharedFileListRef list = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteItems, NULL); if (list) { // We've got the list, so try to append our item // (use kLSSharedFileListItemBeforeFirst vs. // kLSSharedFileListItemLast if desired) LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(list, kLSSharedFileListItemLast, NULL, NULL, (__bridge CFURLRef)url, NULL, NULL); // Did it work? if (item) { // Release the item and flag success CFRelease(item); result = YES; } // Release the list CFRelease(list); } } return result; } 

Using:

 // Create the path to the favorite item to add NSString * itemPath = [@"~/Music" stringByExpandingTildeInPath]; NSURL * itemURL = [NSURL fileURLWithPath:itemPath]; // Insert the item [WhateverClassTheAboveFunctionIsIn appendFavoriteItemWithURL:itemURL]; 
+3
source share

@Asmus: By default, '+ T command' is a shortcut to add a folder in the sidebar in finder. Applescript, denoted by u, works great when the keyboard shortcut "command + T" is assigned manually for other tasks.

The shortcut crashes if it was executed after setting the + T command as a shortcut key to show my other desktop in osx lion (10.7)

0
source share

All Articles