#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { NSArray *args = [[NSProcessInfo processInfo] arguments]; if ([args count] < 2) { printf("USAGE:\n\tuti <filenameExtension>\nEXAMPLE:\n\tuti jpg png\n"); exit(EXIT_SUCCESS); } NSArray *extensions = [args subarrayWithRange:NSMakeRange(1, [args count] - 1)]; for (NSString *filenameExtension in extensions) { NSString *UTI = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)filenameExtension, NULL); NSString *contentType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)UTI, kUTTagClassMIMEType); printf("%s\nUTI: %s\nContentType: %s\n",[filenameExtension UTF8String] , [UTI UTF8String], [contentType UTF8String]); } } return 0; }
--demo--
$ uti jpg png jpg UTI: public.jpeg ContentType: image/jpeg png UTI: public.png ContentType: image/png