OSX: assign extension to content kind

14

6

Here I have a folder containing a bunch of *.mkv files (video, obviously) and *.srt files (subtitles, obviously). I want to keep them within one folder but I don’t want them to be mixed together. It looks like a good idea to visually arrange them into two separate groups.

However, neither extensions are recognised by the system, and they are still put under one group ‘Documents’, which is clearly not what I want.

The question: how to tell the system that all *.mkv file should be treated as ‘Media’ (or ‘Videos’, or whatever the name of the file kind group for video files)?

Thanks.enter image description here

EDIT:

@Daniel, the associated program is MPlayerX and the output of that command is as follows:

imac:Game of Thrones arnold$ mdls "Game of Thrones 1×2.mkv"
kMDItemContentCreationDate     = 2011-12-15 10:31:20 +0000
kMDItemContentModificationDate = 2011-12-27 09:09:55 +0000
kMDItemContentType             = "dyn.ah62d4rv4ge804450"
kMDItemContentTypeTree         = (
    "public.data",
    "public.item"
)
kMDItemDateAdded               = 2011-12-27 09:22:55 +0000
kMDItemDisplayName             = "Game Of Thrones 1×2.mkv"
kMDItemFSContentChangeDate     = 2011-12-27 09:09:55 +0000
kMDItemFSCreationDate          = 2011-12-15 10:31:20 +0000
kMDItemFSCreatorCode           = ""
kMDItemFSFinderFlags           = 0
kMDItemFSHasCustomIcon         = 0
kMDItemFSInvisible             = 0
kMDItemFSIsExtensionHidden     = 0
kMDItemFSIsStationery          = 0
kMDItemFSLabel                 = 0
kMDItemFSName                  = "Game of Thrones 1×2.mkv"
kMDItemFSNodeCount             = 220877659
kMDItemFSOwnerGroupID          = 99
kMDItemFSOwnerUserID           = 99
kMDItemFSSize                  = 220877659
kMDItemFSTypeCode              = ""
kMDItemKind                    = "Video Media"
kMDItemLogicalSize             = 220877659
kMDItemPhysicalSize            = 220880896
imac:Game of Thrones arnold$ 

Weirdly enough, the ‘Item Kind’ does show up as ‘Video Media’. And for a subtitle file is is ‘Subtitle’. Still, it doesn’t help Finder arrange those files correctly for some reason…

Arnold

Posted 2011-12-27T09:05:30.193

Reputation: 741

What program is associated with these files? What's the output of mdls in Terminal for one of these files, e.g. mdls "Game of Thrones episode 2.mkv"? – Daniel Beck – 2011-12-27T11:11:49.727

Is this grouping feature new in Lion? The icons also say "Subtitles" and "Video", respectively, so it shouldn't really be a problem. – slhck – 2011-12-27T11:42:45.567

@slhck It's new in Lion. Icons are 100% images and provided by the associated application, so that doesn't mean anything. Arnold, thanks for the mdls output. Are you using MPlayer OSX or MPlayer OSX Extended? – Daniel Beck – 2011-12-27T11:50:03.187

@DanielBeck, it’s just the regular MPlayerX from the App Store.

– Arnold – 2011-12-27T11:58:23.140

@DanielBeck Ah, I thought it was represented by kMDContentType. What kind of content type is the one listed above though? – slhck – 2011-12-27T12:35:08.737

@slhck Dynamically generated, since the developer of MPlayerX didn't bother to properly assign a type. See my answer. That's why it's a document. – Daniel Beck – 2011-12-27T12:36:38.303

@DanielBeck

see my answer

?? – Arnold – 2011-12-28T02:59:05.553

@ArnoldSakhnov Sorry about that. I posted a rather lengthy answer explaining the process but for some reason it didn't work when I tried and I deleted it for the time being. I probably got some detail wrong. If you're still interested, I can undelete it, but it currently is more of an explanation than a step-by-step guide. – Daniel Beck – 2011-12-28T03:56:59.640

@ArnoldSakhnov Finally I figured out the missing piece. Fixed the answer and undeleted it. – Daniel Beck – 2011-12-28T04:05:08.190

Answers

12

You need to use an application that declares the correct file type association for e.g. the .mkv file name extension.

For example, the system-defined file types in /System/Library/CoreServices/CoreTypes.bundle/Contents/Info.plist declare the following in the Exported Type UTIs section:

enter image description here enter image description here

This allows the system to associate the UTI public.jpeg with the "UTI group" public.image, which is (very likely) what Finder uses for the Images group; the public.filename-extensions equivalent type maps to the file extension.

This allows OS X to determine, that .jpg file has the UTI public.jpeg, and that is a sub-UTI of public.image (and so on, with public.item and public.data). Finder then takes all the files that are (also) public.image and puts them in the same Images group.

The same applies to public.mpeg-4 and public.movie and the filename mapping there.


Unfortunately, the author of MPlayerX didn't bother mapping the UTIs.

He didn't even bother creating proper file types for all the extensions the program supports. That's why in Finder's list view, all .mkv files aren't called e.g. Matroska Video, and have a matching MKV label on their icon, but simply Video Media with a generic Video label. All supported file types are listed by file extension for this "file format", so MPlayerX can open them:

enter image description here

That means, for example, if you prefer playing .m4a files in MPlayerX to iTunes, you lose the descriptive Apple MPEG-4 audio in the Finder's Kind column and get Audio Media instead.


You can fix the grouping by editing the /Applications/MPlayerX.app/Contents/Info.plist file and properly declaring e.g. a mplayerx.video UTI that conforms to public.movie and adding the proper filename extension mapping.

You can fix the Kind column by editing the same file, and properly declaring file types with a better description, and creating an icon file for each.

Just use the Core Types Info.plist file as template, replacing e.g. public.jpeg with your own custom identifier (e.g. mplayerx.video if you don't want proper Kind columns and icons, or mplayerx.mkv if you want them). You need Xcode to edit these files, or convert them to XML editable in any text editor by using plutil -convert xml1 <filename>.

Your changes, which are rather easy to get wrong, will be overridden with every application update.

Alternatively, at least for the Finder Arrange By Kind, you can edit the core types definitions and add your own to it. Make sure to edit a copy of the file and replace it after editing to circumvent permissions issues. Be aware that you'll be editing and replacing core system files (i.e. asking for trouble) by doing this.

A saner solution would be to create a new "dummy" application that simply declares the file type UTIs as Exported Type UTIs. This will be used by OS X's file type database and you can update both OS X and MPlayerX without losing the content type associations. Even if you change e.g. .m4a to MPlayerX, only the Kind column is changed, it's still in the Movie category, due to the declarations in another application independent of the associated application.

So, create a new application e.g. using Automator that doesn't actually do anything when launched, and add the following to its Contents/Info.plist file:

enter image description here

Save in /Applications or so, and restart Finder.

enter image description here

Partial mdls output of the .mkv file, content type provided by the "helper app", item kind provided by the associated player (MPlayerX):

kMDItemContentType             = "superuser.371939.mkv"
kMDItemContentTypeTree         = (
    "superuser.371939.mkv",
    "public.movie",
    "public.audiovisual-content",
    "public.data",
    "public.item",
    "public.content"
)
...
kMDItemKind                    = "Video Media"

Since this is just sloppy platform integration by the developer, you should probably file a bug.

Daniel Beck

Posted 2011-12-27T09:05:30.193

Reputation: 98 421

Very interesting. Learned something new today. So that's why the kMDItemContentTypeTree doesn't add anything useful to the metadata? – slhck – 2011-12-27T12:40:26.273

@slhck Exactly. The system needs a way to associate the file with the content type UTI. That's missing, since it's not in the system by default (like e.g. .mp4 is), and the application adding the file type to the system doesn't declare either the UTI (so it's just dyn.xyz) or the relation (so it's just public.data) either. They'd need to declare the UTI and associate it with public.movie (instead of e.g. public.data). – Daniel Beck – 2011-12-27T12:47:23.843

1Wow! Thanks for such an informative and thorough research on the problem. This is very educational and helpful. I still yet to try out your solution, but I’m sure it’ll work. Very nice! – Arnold – 2011-12-28T09:55:24.543

The hackiest of all hacks is to simply rename the .mkv to .avi gasp!!! I make it slightly less horrific by leaving a Spotlight Comment (in Get Info) saying it's really an mkv. ..this of course assumes your media player is okay with the wrong extension - VLC is down ;) – Joel Mellon – 2013-09-05T02:30:38.253

...I forgot, you can also rename it to .mkv.avi for the least evil workaround but with a slightly less pretty filename. – Joel Mellon – 2013-09-05T02:36:59.843