How to associate MIME type with a handler in OS X?

4

How can one add a new MIME type in OS X?

JAM

Posted 2012-05-08T01:16:28.143

Reputation: 349

It's not clear what you're talking about. Add a new MIME type so that what happens exactly? – David Schwartz – 2012-05-08T02:12:38.857

So that it's handled by some application, see my answer @DavidSchwartz – slhck – 2012-05-08T06:59:16.323

Answers

6

The easiest would be to download and install RCDefaultApp. Go to System Preferences » Default Apps, then the MIME Types tab.

Enter your new MIME type in the text box below, press the + button, and select your handler.


Via command line, you need to edit the ~/Library/Preferences/com.apple.LaunchServices.plist preference list. In its array of LSHandlers, you need to insert a Dictionary containing your new MIME type as:

  • LSHandlerContentTag – the MIME type
  • LSHandlerContentTagClass, which is public.mime-type
  • LSHandlerRoleAll, which specifies the Bundle ID of the application that handles it, e.g. org.videolan.vlc. You find out the bundle ID by inspecting the .app folder and the Info.plist preference list therein.

slhck

Posted 2012-05-08T01:16:28.143

Reputation: 182 472

Awesome answer... Wondering if you were aware of which apps might add in this way? I see none in my LSHandlers that use this format.... Is that because LSHandlerContentType (with values like "public.css" instead of "text/css") is preferred for this? ( https://apple.stackexchange.com/a/9883/206073 seems to suggest such a preference, at least in the case of comparing LSHandlerContentType to the "public.filename-extension" LSHandlerContentTagClass)

– Brett Zamir – 2018-06-20T04:50:18.300

1@BrettZamir Good question – that's beyond my knowledge. It could also be that the default has been changed in the meantime (my answer is from 2012). – slhck – 2018-06-21T05:33:34.843

Is there a way to do the same from the command line? Possibly by editing mime.types? – JAM – 2012-05-08T13:38:11.743

See my updated answer. Are you talking about apache2/mime.types? Not sure if you're supposed to edit that. Can you elaborate a bit why you need to edit it? What's your context? Without context, it's hard to help you. – slhck – 2012-05-08T14:59:42.413

1

To view mime-type of a file in terminal:

file --mime-type -b file-name

Mostafiz Rahman

Posted 2012-05-08T01:16:28.143

Reputation: 119