LSSharedFileListInsertItemURL does not honor the display name or icon
LSSharedFileListInsertItemURL does not honor the display name or icon
- Subject: LSSharedFileListInsertItemURL does not honor the display name or icon
- From: Ben Staveley-Taylor <email@hidden>
- Date: Mon, 17 Dec 2012 17:40:55 +0000
I am trying to add a new item to the Finder Sidebar Favorites kLSSharedFileListFavoriteItems list. The API for doing this, LSSharedFileListInsertItemURL, is not working for me. The Sidebar folder is created, but with a generic folder icon and the name taken from the target folder instead of the supplied display name. Can anyone see the error in the code below? All the API calls are returning noErr or other success codes; there is no error report.
The app is not Sandboxed.
Running on OS X 10.7.5.
Thanks if you can help,
-- Ben
+ (BOOL) createSidebarFavoritesIcon:(NSString *)targetPath displayName:(NSString *)name icon:(NSString *)iconPath
{
BOOL success = NO;
NSURL *folderURL = [NSURL fileURLWithPath:targetPath];
IconRef iconRef = NULL;
if (iconPath != nil)
{
NSURL *iconURL = [NSURL fileURLWithPath:iconPath];
FSRef iconFSRef;
CFURLGetFSRef((CFURLRef)iconURL, &iconFSRef);
OSStatus status = RegisterIconRefFromFSRef('MYAP', 'SFAV', &iconFSRef, &iconRef);
if (status != noErr)
{
NSLog(@"%s: RegisterIconRefFromFSRef failed, error code %d", __FUNCTION__, (int)status);
}
}
// Create a reference to the shared file list.
LSSharedFileListRef favoritesList = LSSharedFileListCreate(kCFAllocatorDefault,
kLSSharedFileListFavoriteItems,
NULL);
if (favoritesList != NULL)
{
LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(favoritesList,
kLSSharedFileListItemLast,
(CFStringRef)name, // inDisplayName -- defaults to the folder name
iconRef,
(CFURLRef)folderURL,
NULL, // inPropertiesToSet
NULL // inPropertiesToClear
);
if (item != NULL)
{
success = YES;
CFRelease(item);
}
CFRelease(favoritesList);
}
return success;
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden