Remove double 'Open With' Entries from OS X Finder menu
2012-11-29
If you find that your Mac's 'Open With' menu is growing cluttered with identical menu entries for the same application, this indicates that your Launch Services database is confused.
In the normal course of action your computer scans for entries to merge into this database at boot time, and then at login for the user domains. The Finder updates it with new application information, as and when new App or Framework bundles are encountered during it's normal operation. Unfortunately this database does seem to be capable of becoming persistently corrupted, which will result in symptoms like a duplicate-riddled 'Open With' menu, or incorrect or inconsistent Filetype/Application associations.
On Mountain Lion, you can interact with the system database from the shell, using the lsregister utility. Run it without arguments to get basic usage instructions. It is not on any default, paths, it's buried away inside /System/Library/Frameworks/CoreServices.framework .
/System/Library/Frameworks/CoreServices.framework
/Versions/A/Frameworks/LaunchServices.framework
/Versions/A/Support/lsregister -dump
will show you the current database in human readable form. To scrap and rebuild the database completely you might do something like this
/System/Library/Frameworks/CoreServices.framework
/Versions/A/Frameworks/LaunchServices.framework
/Versions/A/Support/lsregister -kill -all u,s,l -r -v
The -domain argument there is specifying that we should recursively ( -r ) scan for bundle directories in the the u ser, s ystem and l ocal domains (i.e. "~/ /" , "/System/ ", and "/ " ) and register their document type bindings and other information with the Launch Services agents, which will update their database with this information. The -v switch turns on progress logging, which is all done to stderr.
If you're in the habit of installing apps or library bundles to some alternative roots than the builtin domain types, you can add those paths to the command, instead of the domain flags.