How can I make OS X recognize new file extensions?
UTIs and Launch Services


  Where is the list of “known” file types stored?


The official term for "file types" is
Uniform Type Identifiers
(UTIs), and the database of UTIs is maintained by
Launch Services.

Using the Terminal,
you can view the contents of the Launch Services database using the lsregister tool, which is stored at:

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister


Instead of specifying that long path every time you want to run lsregister, you can temporarily add its directory to your PATH:

PATH=/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support:"$PATH"


and then you can run lsregister by simply entering:

lsregister


To view the contents of the Launch Services database:

lsregister -dump




Declaring New UTIs


  Is there a way to make OS X recognize new file types?


This Apple article,
"Declaring New Uniform Type Identifiers",
provides useful information on how to do this. Here's the complete process:

1. Create a dummy application

Create a dummy application to register with Launch Services:


Open AppleScript Editor (located in OS X's Utilities folder).
Save a new empty script somewhere (eg: on your Desktop), setting its File Format to Application.


2. Open its Info.plist file


Locate your new dummy application in the Finder.
Right-click on it, and select Show Package Contents from the popup menu.
Open its Contents folder.
Open the Info.plist file in a text editor (eg: TextEdit).


3. Add your new UTI

There's a choice of two keys:


UTExportedTypeDeclarations – for your own custom filename extensions.
UTImportedTypeDeclarations – for filename extensions which already exist but aren't recognised by OS X.


Choose the key which is most appropriate for your needs.

Then in the Info.plist file, before the final two lines (&lt;/dict&gt;&lt;/plist&gt;), add this code:

&lt;key&gt;KEY&lt;/key&gt;
&lt;array&gt;
    &lt;dict&gt;
        &lt;key&gt;UTTypeIdentifier&lt;/key&gt;
        &lt;string&gt;IDENTIFIER&lt;/string&gt;
        &lt;key&gt;UTTypeTagSpecification&lt;/key&gt;
        &lt;dict&gt;
            &lt;key&gt;public.filename-extension&lt;/key&gt;
            &lt;array&gt;
                &lt;string&gt;EXTENSION&lt;/string&gt;
            &lt;/array&gt;
        &lt;/dict&gt;
    &lt;/dict&gt;
&lt;/array&gt;


making the following changes:


Replace KEY with your chosen key (either UTExportedTypeDeclarations or UTImportedTypeDeclarations).
Replace IDENTIFIER with a suitable reverse-DNS identifier:

Exported – Something like com.mycompany.mytype
Imported – For id Software's
Doom WAD format, a suitable identifier would be com.idsoftware.wad

Replace EXTENSION with the filename extension (without the leading dot), eg: wad.


This is the minimum code necessary for Launch Services to accept your new UTI.
You can also add the following optional properties:


UTTypeConformsTo – See the Appendix below.
UTTypeDescription – A user-visible description, which will be displayed in the Finder.
UTTypeIconFile – If you add an Apple Icon Image
file to the Contents/Resources folder in your dummy application, and add its filename in this property,
then files which have your new filename extension will use this icon.
UTTypeReferenceURL – The URL of a reference document describing this type.


Here's a complete example showing all the optional properties:

&lt;key&gt;UTImportedTypeDeclarations&lt;/key&gt;
&lt;array&gt;
    &lt;dict&gt;
        &lt;key&gt;UTTypeIdentifier&lt;/key&gt;
        &lt;string&gt;com.idsoftware.wad&lt;/string&gt;
        &lt;key&gt;UTTypeTagSpecification&lt;/key&gt;
        &lt;dict&gt;
            &lt;key&gt;public.filename-extension&lt;/key&gt;
            &lt;array&gt;
                &lt;string&gt;wad&lt;/string&gt;
            &lt;/array&gt;
        &lt;/dict&gt;
        &lt;key&gt;UTTypeConformsTo&lt;/key&gt;
        &lt;array&gt;
            &lt;string&gt;public.data&lt;/string&gt;
        &lt;/array&gt;
        &lt;key&gt;UTTypeDescription&lt;/key&gt;
        &lt;string&gt;Doom WAD file&lt;/string&gt;
        &lt;key&gt;UTTypeIconFile&lt;/key&gt;
        &lt;string&gt;DoomWAD.icns&lt;/string&gt;
        &lt;key&gt;UTTypeReferenceURL&lt;/key&gt;
        &lt;string&gt;http://en.wikipedia.org/wiki/Doom_WAD&lt;/string&gt;
    &lt;/dict&gt;
&lt;/array&gt;


4. Register your new UTI with Launch Services

Run this command in the Terminal:

lsregister &lt;PATH_TO_APP&gt;


replacing &lt;PATH_TO_APP&gt; with the path to your dummy application, eg:

lsregister ~/Desktop/MyDummyApp.app


If you now create a file with your new filename extension, and then select it in the Finder
and hit Enter, the Finder should automatically select only the filename part, not the extension.

If you view the contents of the Launch Services database:

lsregister -dump


you should find your new UTI listed:

type    id:            50364
        bindableKey:   12608
        generation:    1
        uti:           com.idsoftware.wad
        description:   Doom WAD file
        flags:         imported  active  apple-internal  untrusted
        icon:          DoomWAD.icns
        conforms to:   public.data
        tags:          .wad


If you later want to unregister your new UTI, pass the -u option to lsregister:

lsregister -u ~/Desktop/MyDummyApp.app




Appendix: UTI hierarchy and conformance

OS X declares a hierarchy of UTIs which are listed here:
System-Declared Uniform Type Identifiers.

Here are a few UTIs in the hierarchy:


public.content

public.text

public.rtf
public.html
public.xml
public.plain-text
public.source-code

public.c-source
public.c-header
com.sun.java-source


public.image

public.jpeg
public.tiff
public.png

public.audiovisual-content

public.movie
public.audio




Each UTI "conforms to" its parent UTI:


  For example, the UTI public.html, which defines HTML text, conforms to the
  base text identifier, public.text. In this case, conformance lets applications
  that can open general text files identify HTML files as ones it can open as well.
  (ref)


When creating a new UTI, it's a good idea to set the UTTypeConformsTo property to one
of the existing UTIs.

For example, if your new UTI is a type of source code,
then you should set the UTTypeConformsTo property to public.source-code,
so that it can be opened by any applications which can open
public.source-code or public.plain-text or public.text files.