Re: Where did the icon come from?
Re: Where did the icon come from?
- Subject: Re: Where did the icon come from?
- From: Eric Gorr <email@hidden>
- Date: Fri, 16 Jul 2010 18:50:39 -0400
On Jul 16, 2010, at 6:31 PM, James Walker wrote:
> On 7/16/2010 2:45 PM, Eric Gorr wrote:
>> Thanks, but I wasn't specific enough.
>>
>> What I am looking for is something like this:
>>
>> $WhoProvidedIcon /Path/To/file.myex
>>
>> UTI: com.myapplication.document
>> PLIST: /path/to/myapplication.app/Contents/Info.plist
>> ICON: /path/to/myapplication.app/Contents/Resources/BaseDoc.icns
>
> Perhaps you could get some of this information by first using UTTypeCreateAllIdentifiersForTag to get the possible UTIs for the extension, and then passing each UTI to UTTypeCopyDeclaringBundleURL and UTTypeCopyDeclaration.
Gotta love it when you learn about functions you were unaware of previously.
I don't think I need UTTypeCreateAllIdentifiersForTag....NSWorkspace should give me the UTI for the file.
So, This code is probably all I need:
NSString* uti = [ws typeOfFile:@"/Users/egorr/Desktop/file.vwx" error:&error];
NSLog( @"UTI: %@", uti );
NSLog( @"UTI localized description: %@", [ws localizedDescriptionForType:uti] );
NSLog( @"UTI error description: %@",[error localizedDescription] );
NSURL* utiDeclarationURL = (NSURL*)UTTypeCopyDeclaringBundleURL( (CFStringRef)uti );
NSLog( @"UTI declaration URL: %@", utiDeclarationURL );
NSDictionary* utiDeclaration = (NSDictionary*)UTTypeCopyDeclaration( (CFStringRef)uti );
NSLog( @"UTI declaration: %@", utiDeclaration );
(Also gotta love the toll-free bridging...)
Of course, I'll edit the obtaining the uti to take a path from the command line.
Doesn't quite give me the path to the icon, but does get me to the application which the declaration came from for the UTI.
As long as all of this matches what the OS will do, then I should be good to go for my situation.
p.s. Yes, I know that the icon for a file may not be an icon at all, but an image provided by a Quick Look plugin...but in my case, I know that it is an icon and not something provided by a Quick Look plugin. But, it would be interesting if one could determine exactly where the image for the file was coming from. The code above won't do that.
_______________________________________________
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