duti is a command-line tool written by Andrew Mortensen, designed to set default applications for document types and URL schemes on Mac OS X.
Document types on Mac OS X are defined by what Apple calls Uniform Type Identifiers, or UTIs. HTML files, for example, have a UTI of public.html. Microsoft Word documents are described by the UTI com.microsoft.word.doc. Apple provides many UTIs with Mac OS X, but developers are free to define their own, as long as the UTI is unique to that document type.
duti's name means "default for UTI."
duti can read and apply settings from a specially formatted text file, from an XML property list, or from standard input. In typical use, duti would read and apply settings from a file a line at a time.
To set the default application for a document type, duti needs three things:
To set the default application for a URL scheme, duti needs just two things:
A simple settings file, then, would look like this:
# Set Safari as the default handler for HTML files, # set TextEdit as the default handler for files with .patch extensions, # and set Firefox as the default handler for feed:// URLs. # # blank lines and lines beginning with a '#' are ignored # # bundle id UTI/ext/MIME type role com.apple.Safari public.html all com.apple.TextEdit .patch editor # bundle id URL scheme org.mozilla.Firefox feed
Applying the settings in the file might look something like this:
localhost% cat /Library/Settings/html_handler.duti # Set Safari as the default handler in all roles for HTML files # # blank lines and lines beginning with a '#' are ignored # # bundle id UTI role com.apple.Safari public.html all localhost% duti /Library/Settings/html_handler.duti localhost%
duti can also apply settings from an XML property list (plist). See the manual page section below for details regarding the use of plists with duti.
If the path given to duti is a directory, duti will apply settings from all visible files found in the directory, in lexical order. This allows the administrator the option of overriding settings depending on the purpose of the system.
In this example, duti applies settings from a directory. The -v flag makes duti run verbosely, so you can see what settings it applies.
localhost% ls /Library/Settings MSOffice.plist html_handler.duti realplayer.duti localhost% duti -v /Library/Settings Applying settings from from /Library/Settings/MSOffice.plist setting com.apple.TextEdit as handler for com.microsoft.word.doc Applying settings from /Library/Settings/html_handler.duti setting com.apple.Safari as handler for public.html Applying settings from /Library/Settings/realplayer.duti setting com.real.RealPlayer as handler for com.real.realaudio setting com.real.RealPlayer as handler for com.real.realmedia localhost%
duti.1 -- manual page for duti