[solved, but a little dirty] Re: Human readable file type?
[solved, but a little dirty] Re: Human readable file type?
- Subject: [solved, but a little dirty] Re: Human readable file type?
- From: Allan Odgaard <email@hidden>
- Date: Sun, 7 Jul 2002 16:43:02 +0200
On sxndag, juli 7, 2002, at 02:47 , Allan Odgaard wrote:
I need to display a human readable filetype, similar to how the "Show
Info" of the Finder does (e.g. "MP3 Audio File").
I was pointed toward LaunchServices, but I can't really find any useful
documentation on that, so until I do this is what I use (if anyone
should be interested):
- (NSString *)humanReadableFiletype:(NSString *)path
{
NSString *res = nil, *openWith, *filetype;
if([[NSWorkspace sharedWorkspace] getInfoForFile:path
application:&openWith type:&filetype])
{
NSBundle *bundle;
NSDictionary *info;
NSArray *types;
if((bundle = [NSBundle bundleWithPath:openWith]) && (info =
[bundle infoDictionary]) && (types = [info
objectForKey:@"CFBundleDocumentTypes"]))
{
int typeCnt;
for(typeCnt = 0; typeCnt < [types count] && res == nil; typeCnt++)
{
NSDictionary *type = [types objectAtIndex:typeCnt];
NSArray *extensions = [type objectForKey:@"CFBundleTypeExtensions"];
if(extensions == nil)
continue;
int extensionCnt;
for(extensionCnt = 0; extensionCnt < [extensions
count] && res == nil; extensionCnt++)
{
if([filetype isEqualToString:[extensions
objectAtIndex:extensionCnt]])
res = [type objectForKey:@"CFBundleTypeName"];
}
}
}
if(res == nil)
res = [[NSFileManager defaultManager] displayNameAtPath:openWith];
}
return res ? res : @"(unknown file)";
}
It works nicely, except that TextEdit has registered many of its types
as "NSStringPBoardType" -- Finder show these types as "Plain text file".
So definetely Finder doesn't do the above... I'm still looking forward
to a better solution...
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.