Created
March 22, 2012 09:48
-
-
Save simonwhitaker/2157405 to your computer and use it in GitHub Desktop.
Lists the UTIs for a given list of file extensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <CoreServices/CoreServices.h> | |
#import <libgen.h> | |
/* | |
convert-ext-to-uti | |
Shows the Uniform Type Identifier(s) (UTI) for a | |
file type based on its file extension. Output is | |
a tab-separated tuple of (extension, UTI) per | |
line. | |
SYNOPSIS | |
convert-ext-to-uti EXT [EXT...] | |
MORE INFO | |
http://en.wikipedia.org/wiki/Uniform_Type_Identifier | |
EXAMPLE USAGE | |
$ ./convert-ext-to-uti zip tgz | |
zip public.zip-archive | |
tgz org.gnu.gnu-zip-tar-archive | |
*/ | |
int main(int argc, char *argv[]) { | |
if (argc == 1) { | |
printf("Usage: %s EXT [EXT...]\n", basename(argv[0])); | |
return 1; | |
} | |
@autoreleasepool { | |
for (int i = 1; i < argc; i++) { | |
CFStringRef ext = CFStringCreateWithCString(kCFAllocatorDefault, argv[i], kCFStringEncodingUTF8); | |
CFArrayRef types = UTTypeCreateAllIdentifiersForTag(kUTTagClassFilenameExtension, ext, nil); | |
for (CFIndex idx = 0; idx < CFArrayGetCount(types); idx++) { | |
CFStringRef type = CFArrayGetValueAtIndex(types, idx); | |
printf("%s\t%s\n", [(__bridge NSString*)ext UTF8String], [(__bridge NSString*)type UTF8String]); | |
} | |
CFRelease(ext); | |
CFRelease(types); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment