• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[solved, but a little dirty] Re: Human readable file type?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[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.
  • Follow-Ups:
    • [solved, really!] Re: Human readable file type?
      • From: Allan Odgaard <email@hidden>
References: 
 >Human readable file type? (From: Allan Odgaard <email@hidden>)

  • Prev by Date: Re: accessor generation???
  • Next by Date: Re: FW: strcat
  • Previous by thread: Human readable file type?
  • Next by thread: [solved, really!] Re: Human readable file type?
  • Index(es):
    • Date
    • Thread