I try to read information about icons that are shown in finder on left source list. I tried already NSFileManager
with following options
NSURLEffectiveIconKey
icon read is not the same as in finderNSURLCustomIconKey
- returns nilNSURLThumbnailKey
- returns nilNSThumbnail1024x1024SizeKey
- returns nilI managed to read all mounted devices using NSFileManager but I have no clue how to read icons connected with devices? Maybe someone has any idea or a hint.
I also tried to use
var image: NSImage = NSWorkspace.sharedWorkspace().iconForFile((url as! NSURL).path!)
but it returns the same image as NSURLEffectiveIconKey
Thanks!
First, the proper way to query which volumes are shown in the Finder's sidebar is using the LSSharedFileList API. That API also provides a way to query the icon:
LSSharedFileListRef list = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteVolumes, NULL);
UInt32 seed;
NSArray* items = CFBridgingRelease(LSSharedFileListCopySnapshot(list, &seed));
CFRelease(list);
for (id item in items)
{
IconRef icon = LSSharedFileListItemCopyIconRef((__bridge LSSharedFileListItemRef)item);
NSImage* image = [[NSImage alloc] initWithIconRef:icon];
// Do something with this item and icon
ReleaseIconRef(icon);
}
You can query other properties of the items using LSSharedFileListItemCopyDisplayName()
, LSSharedFileListItemCopyResolvedURL
, and LSSharedFileListItemCopyProperty()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With