When you open a document or click a link in OS X, the system launches a program that can read it. While OS X provides options to change the programs associated with documents, there is no option to clear all application associations for a file type.
The resource that OS X uses to associate file types (e.g., TXT and PDF) or protocols (e.g., HTTP or FTP) with applications that can handle them is the launch services database. When an application is launched for the first time, the system scans its file-handling abilities and stores them in this database so the application can then be used to quickly open documents it was built to handle. While done automatically by the system, you can manually do this by using the "lsregister" Terminal command.
For instance, to register a program called Appname with the launch services, you can run the following command in the Terminal:
`locate lsregister` /Applications/Appname.app
Note: The "lsregister" command itself is buried deep in an application framework, so instead of typing the very long path to the command in the Terminal, we can use the `locate lsregister` notation as a shortcut. If this shortcut does not work, then it is likely that the system's "locate" database is not properly built. In this case, run the command "sudo /usr/libexec/locate.updatedb" in the Terminal and provide your password when prompted. The command should take a moment or two to complete, after which the `locate lsregister` shortcut should work.
While you can run the "lsregister" command in this manner for each application on the system, you can also supply the command with the "-seed" flag as shown below, which will tell the system to scan common areas where applications are stored (e.g., the /Applications or /username/Applications folders), and register any that are found in these areas:
`locate lsregister` -seed
Again, the system should automatically do this so running these commands manually is not necessary; however, understanding that the system registers applications individually like this helps in tackling a limitation of the file-handling in OS X, which is how one might clear a custom file association with applications in OS X, which may be manually set for file types that the system cannot recognize.
For instance, if you have a file called "test.asdf," then the system will likely not know how to handle the "asdf" file type and will prompt you to select an application with which to open it.
Upon selecting an application, the system will initially just store the application association in an extended attribute for the file and not update the central launch services database (keep this in mind for later); however, if you get information on the file and click the "Change All..." button in the "Open With" section of the document, then the launch services will be updated to associate that file type with the selected application.
This behavior is quite standard and is regularly used on OS X, but it does come with one problem, which is that once the file type is part of the launch services then the system will handle it with one program or another, so while you can change the application used to open the file, Apple provides no way to clear this so the system prompts you for an application to use when you open the file.
This default behavior may be desired in most instances, but sometimes people may wish to clear file handling associations and force the system to ask you how to handle the document when you next open it.
Luckily, even though Apple does not provide a way to do this, understanding that the launch services handle file types on a per-application basis allows us to use applications that do not handle files as intermediaries for clearing file types from the launch services. Here is how to do this:
- Let's first assume you have a file "test.asdf" associated with TextEdit, so select the file and press Command-I to get information on it (you should see "TextEdit" selected in the "Open With" section of the info window).
- Click the drop-down menu in the "Open With" section and choose "Other," and then select a program like Chess or Calculator to handle the file. These programs are not built to handle any protocols or file types, so by default they are not used by the launch services at all.
- Now click the "Change All..." button in the information window to register this file type with the program in the launch services.
At this point the "asdf" document type will no longer be associated with TextEdit, but instead will now be associated with Chess or Calculator so when you open it then either of those applications also open and likely give you an error stating the program cannot handle files. This is undesired, so the next step is to clear this association, which can be done by unregistering that application from the launch services database. Remember we can do this manually with the "lsregister" Termianl command, so run the following in the Terminal:
`locate lsregister` -u /Applications/Calculator.app
Unregistering the Calculator (or Chess) applications in this manner will not hurt anything since these programs do not handle files or protocols, but the removal of them from the launch services will clear the "asdf" file type associated with them.
After this is done, the "asdf" file type should be cleared out of the launch services database, and when you open them the system should now ask you what to do.
The one final step is to clear the extended attributes on the initial files you opened. The presence of the extended attribute on these files may still cause them to be open with the specified application even though the launch services are cleared, so to remove the extended attribute from these files, follow these steps:
- Open the Terminal and type the following, followed by a single space:
xattr -d com.apple.ResourceFork
- Drag the desired file to the Terminal window, which should fill out the file's full path in the same line as the command.
- Press Enter to run the command and delete the resource fork.
This procedure will not be necessary for all files, but just those that you specifically chose an application to open with.