Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a method for associating file types with applications via terminal? I thought ~/Library/Preferences/ might do it, and I also have seen: Why is a command line change to ~/Library/Preferences/ not effective immediately? but I can't seem to get it working.

I guess I'm looking for a way to imitate what the GUI does when someone uses it to change association types, it seems to work instantly there...

share|improve this question
up vote 5 down vote accepted

You can edit ~/Library/Preferences/ in a text editor after converting it to XML:

plutil -convert xml1 ~/Library/Preferences/

Then add entries like this to the LSHandlers array:


You can use mdls to see the UTIs of file types and something like osascript -e 'id of app "AppName"' to see the bundle identifiers of applications.

You can apply changes to by restarting. Logging out and back in isn't enough.

I also use duti though. I have saved a file like this (with about 100 lines) as ~/.duti:

org.gnu.Emacs public.plain-text all # .txt, .text, plain text files without an extension
org.gnu.Emacs public.unix-executable all # executable scripts
com.SequentialX.Sequential .jpg all
org.videolan.vlc .mkv all

I have a launchd agent that runs duti ~/.duti automatically when ~/.duti is changed.

You can normally use filename extensions (like .jpg) instead of a UTIs (like public.jpg) to specify file types. duti converts the extensions to UTIs that also apply to other extensions (like .jpeg). For some extensions like .mkv and .tex, the UTI depends on what application registered the extension first.

The latest version of duti (1.5.1) only includes source code, but 1.5.0 also includes an installer.

share|improve this answer

Check out duti:

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 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."

share|improve this answer

Short answer: A file's application association is stored in the file's resource fork, and Apple provides two utilities (Rez and DeRez) which allow manipulation of resource forks., but this is not for the faint of heart.

For more details, this question is answered very thoroughly at Super User:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.