I have for some time been suffering a minor (but it seems not uncommon) annoyance with the “Open With” menu when I right click on a document in the Finder. Over time a number of old and duplicate items have worked there way into the list. It seems that OS X has at some point spotted additional copies of applications and helpfully added them to the menu. VMWare Fusion has also made a contribution adding some applications from an old Windows XP image before I figured out how to disable that option. The following is what I was seeing when I right-clicked on a
Now I like Pixelmator and Evernote but there is no way I really want to see them listed five times and I have never wanted to open a pdf using Internet Explorer. I cannot say for sure when I first noticed this problem but I do know it is worse since I upgraded to Mountain Lion.
The Launch Services API is what controls how a running application can open a document in another application. When you open a file in the Finder what actually happens under the covers is that the Finder uses the Launch Services API to request that the associated application is used to open the file on behalf of the user.
In order to be able to respond to such requests Launch Services maintains a database in which it records all registered applications and the kinds of documents each application can open. (If you are curious you can find this database in
~/Library/Preferences/com.apple.LaunchServices.plist.) The system takes care of registering applications with Launch Services automatically in the following situations:
- When the system boots or a new user logs in the Applications directory is scanned and any new applications are registered.
- The Finder will automatically register any new applications as it “becomes aware of them” such as when they are installed.
- When the user opens a document which does not have a preferred application registered in the launch services database they will be asked to select one by the Finder which is then registered for future use.
Luckily you do not really need to know anything about Launch Services to clean up the “Open With” menu.
Command-Line Utility – lsregister
The easiest way to interact with the launch services database is to use the
lsregister command-line utility from the terminal. Unfortunately it is buried deep down in a system library subdirectory:
$ cd /System/Library/Frameworks/CoreServices.framework/Versions/Current/Frameworks/LaunchServices.framework/Versions/Current/Support/
You can of course just search from the command-line if you are having problems finding it on older versions of OS X:
$ find /System/Library/Frameworks -name lsregister /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister
The two directory paths although slightly different are actually equivalent as the
Current directory is actually just a link to the
A directory. Whichever path you use once you have set it as your current working directory you can reset the database with the following command:
$ ./lsregister -kill -r -all system,local,user
The above commands were tested on OS X Mountain Lion (v10.8.2), earlier OS versions stored the lsregister command in different locations and used different command-line options (see below).
If you google for “lsregister” or for “Open With Duplicates” you will find that most people will recommend the following command to reset the launch services database.
$ ./lsregister -kill -r -domain system -domain local -domain user
As far as I can tell the two command-line variations are equivalent and do the same thing. The latter of the two (using -domain) no longer appears as a valid command-line option (use ./lsregister -h to see all options) but still works as of Mountain Lion (v10.8.2). If you running an earlier version of OS X you may need to use this variation.
I did not find it necessary to restart the Finder or reboot for the changes to take effect but your mileage may indeed vary.
If you add the -v option for verbose output to the above lsregister command you can watch as the system library and application directories are scanned and each application is registered. Do not be alarmed by the -10811 error messages, they are just indicating that a non-application file or directory was found and could not be registered which is harmless.
... lsregister: registered /Applications/Twitterrific.app lsregister: error -10811 registering /Applications/Utilities lsregister: error -10811 registering /Applications/Utilities/.DS_Store lsregister: error -10811 registering /Applications/Utilities/.localized lsregister: registered /Applications/Utilities/Activity Monitor.app ...
Finally Back To Normal
After resetting the launch services database my “Open With” menu is finally back to a clean and useful size. The following is what I now see for a
Several days later my menu is still looking clean so I am hoping it will now stay that way. Unfortunately it seems that this is a long standing OS X problem even though it only seems to have recently started to annoy me.