I want to get the Finder "Kind" for a file. For example, for a file "foo.css", I want the string "CSS style sheet".
So far, I'm doing something like this:
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: filename];
NSString *utiType;
NSError *error;
BOOL success = [fileURL getResourceValue: &utiType
forKey: NSURLTypeIdentifierKey
error: &error];
if (!success) {
NSLog(@"failure during reading utiType: error = %@", error);
return;
}
NSString *utiDescription = (__bridge NSString *) UTTypeCopyDescription((__bridge CFStringRef) utiType);
if (utiDescription) {
// use utiDescription here...
}
This gives me the human-readable name of the UTI, which works well in some cases ("foo.html" gives "HTML text"), but for CSS files it returns nil, so it's clearly not the same thing that the Finder is showing in the "Kind" column.
How do you get the Kind of a file?
Try
LSCopyKindStringForURL
, passing the file URL.