JarBundler - Associating Files with your Application

The nested <documenttype> task adds the appropriate elements to the Info.plist file to associate a set of document file types with the application. This association means that this application:

It is important to note that these association are done by the operation system, your application must supply to proper code to handle the open document requires.

Also see Apple Developer Documentation on the CFBundleDocumentTypes key.

NB: You must use at least one of the attributes "extensions", mimetypes or "ostypes". Any combination of these three may, of course, be used.

DocumentType Task Attributes

Attribute Description
name An application's unique name for this document type. For example, "Text Document" or "Raw Data Document"
NB: Required attribute
extensions A comma or space delimited string of filename extensions. Do not specify the leading period. To open documents with any extension, specify an extension with a single asterisk "*".
ostypes A comma or space delimited string of Mac OS types. Each value contains a four-letter type. To open documents of any type, include four asterisk characters "****" as the type code. These codes are equivalent to the legacy type codes used by Mac OS 9. Currently, OS Types with leading or trailing spaces or commas cannot be processed.
mimetypes A comma or space delimited string of mime-types.
UTI A comma or space delimited string of Uniform Type Identifier (UTI) strings for the document. UTIs are strings that uniquely identify abstract types. They can be used to describe a file format or data type but can also be used to describe type information for other sorts of entities, such as directories, volumes, or packages. For more information on UTIs, see the header file UTType.h, available as part of LaunchServices.framework in Mac OS X v10.3 and later. Also see the Apple Developer Connection document "Simplifying Data Handling with Uniform type Identifiers".
iconfile Specifies the name of an icon file used to associate with this document type. This icon file is copied into the application bundle. These icons will be used for the document look if this application is associated as the default application for this document type use the Finder "Get info" command with the document.
role This key specifies the application's role with respect to the type. The value can be Editor, Viewer, Shell, or None. See "Document Configuration" for descriptions of these values.
NB: Required attribute
bundle Used with extention and iconfile attributes to specify to Finder that a directory tree be treated and displayed as a single document. See "Property List Key Reference", look for the document type key LSTypeIsPackage.
NB: Boolean attribute, takes "true" or "false", default is "false"

Example

The following example shows four document types being associated with a JarBundler built Mac OS X application. The first document type associates HTML files using the file extensions html and htm. The application also provides a custom icon file which can be used by Finder to render files with these two extensions, if this application is chosen as the default application.

The second document type creates an association with files with the extension rtf. In this case these files will be rendered by the Finder using a system default icon or an icon set from another application. The application is also telling the Finder that rtf files can be viewed but not edited.

The third document type associates a mime-type for JPEG and PNG images. Again, the application is declaring that it can only view files of this mime-type.

The last document type is a bit interesting using the bundle attribute to designate a directory, which has an extension, as a document. The application has an icon set which will be used by the Finder to render this directory. The directory will not be seen from the Finder as a folder and can be copied and renamed as a single unit. This structure can be very useful or creating complex associations of files which should be treated as a unit. The content of the document bundle can be viewed using a control-click and choosing "Show Package Contents...".

A document bundle has proven very useful in my own development work bring UNIX applications onto to Mac OS X platform where the application would require several input file and create a myriad of small output files.



  <jarbundler dir="release"...> 
                
      <documenttype name="Hello World HTML document"
                    extensions="html htm" 
                    iconFile="icons/html.icns"
                    role="Editor"/>
                     
      <documenttype name="Hello World RTF document"
                    extensions="rtf" 
                    role="Viewer"/>

      <documenttype name="Hello World images"
                    mimetypes="image/jpeg image/png" 
                    role="Viewer"/>

      <documenttype name="Hello Project document"
                    extensions="hello"
                    iconFile="icons/Hello Document.icns"
                    bundle="true"
                    role="Editor"/>
                    
  </jarbundler>