You could add Finder Sidebar Favorite item programmatically. Maybe this can help:
+ (void) addDriveToFinderFavorites
{
@try
{
// this method will freeze at CFBridgingRetain if called on main queue
assert(![NSThread isMainThread]);
NSString* path = SREG.context.mountPath;
CFURLRef url = CFBridgingRetain([NSURL fileURLWithPath:path]);
// Create a reference to the shared file list.
LSSharedFileListRef favoriteItems = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteItems, NULL);
Log(kLogCore, @"Attempting to add mount disk to Finder Favorites sidebar: %@", X(path));
BOOL alreadyAddedToFinder = [self isMountUrl:url addedTo:favoriteItems];
if (favoriteItems && !alreadyAddedToFinder)
{
Log(kLogCore, @"Adding mount disk to Finder Favorites sidebar.");
LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(favoriteItems,
kLSSharedFileListItemLast, NULL, NULL,
url, NULL, NULL);
if (item)
{
CFRelease(item);
}
}
if (!favoriteItems)
{
CDLogWarn(kLogCore, @"FinderFavoritesSidebar: No favorite items found.");
}
if (alreadyAddedToFinder)
{
Log(kLogCore, @"FinderFavoritesSidebar: item already added");
}
CFRelease(favoriteItems);
}
@catch (NSException* e)
{
CDLogError(kLogCore, @"Exception trying to add drive to Finder favorites sidebar: %@", e);
}
}
+ (void) removeDriveFromFinderFavoritesForMountPath:(NSString*)path
{
@try
{
assert(![NSThread isMainThread]);
Log(kLogCore, @"Removing Finder sidebar path: %@", X(path));
LSSharedFileListRef favoriteItems = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteItems, NULL);
CFArrayRef favoriteItemsCfArray = LSSharedFileListCopySnapshot(favoriteItems, NULL);
NSArray* favoriteItemsArray = (__bridge NSArray*) favoriteItemsCfArray;
NSString* mountPath = [NSString stringWithFormat:@"%@/", path];
for (id item in favoriteItemsArray)
{
if ([[[[item valueForKey:@"_internalItem"] valueForKey:@"bookmark"] description] hasSuffix:mountPath])
{
LSSharedFileListItemRef k = (__bridge LSSharedFileListItemRef) (item);
LSSharedFileListItemRemove(favoriteItems, k);
return;
}
}
}
@catch (NSException* e)
{
CDLogError(kLogCore, @"Exception in removeDriveFromFinderFavoritesForMountPath: %@", e);
}
}
+ (BOOL) isMountUrl:(CFURLRef)url addedTo:(LSSharedFileListRef)favoriteItems
{
NSString* lastPathComponent = ((__bridge NSURL*) url).lastPathComponent;
NSArray* favoriteItemsArray = (__bridge NSArray*) LSSharedFileListCopySnapshot(favoriteItems, nil);
for (NSUInteger i = 0; i < favoriteItemsArray.count; i++)
{
LSSharedFileListItemRef currentItemRef = (__bridge LSSharedFileListItemRef) favoriteItemsArray[i];
NSString* name = (__bridge NSString*) LSSharedFileListItemCopyDisplayName(currentItemRef);
if ([name isEqualToString:lastPathComponent])
{
return YES;
}
}
return NO;
}