Getting rid of Open With duplicates
February 16th, 2013 at 9:13 pm by Dr. Drang
This is the problem: You want to open a file using something other than the default application. You right-click its icon in the Finder, choose Open With, and a submenu pops up with an absurd number of duplicate entries.
When you first noticed the duplicates, it was just one or two and you didn’t want to take the time to find out how to fix it, but now you’re kind of pissed at your Mac for being so stupid. You don’t have two copies of Acorn or Skim or PDFpenPro—why is it showing duplicates?
I don’t want to give the impression that I have some unique insight into this problem or its solution. If you know what to search for, you can find it in several places on the internet, including this entry at Stack Overflow, this one at TUAW, and this one at MacLife. But if, like me, you’ve been living with this problem for a while and don’t want to ever have to go searching for the solution again, here’s a little something you can add to your .bashrc:
# Quick way to rebuild the Launch Services database and get rid
# of duplicates in the Open With submenu.
alias fixopenwith='/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user'
Now you can get rid of the duplicates from the Terminal by running
fixopenwith
You may need to follow that up with a
killall Finder
but that wasn’t necessary for me on Mountain Lion.
The duplicate entries in the Open With submenu are caused by some corruption of the Launch Services database. The lsregister command, which is buried many layers under the /System/Library folder, will rebuild the database if you invoke it with the right options. By saving both the path and the options as an alias with (I hope) an easy-to-remember name, I’ll always have a solution at my fingertips.
As a bonus, fixopenwith also gets rid of the duplicate entries in the AppleScript Editor’s Open Dictionary window. It must use the same database.
I know this kind of cleanup can be done by apps like Onyx, but I find its user interface offputting. To me, it’s much simpler to just have an alias that does the one thing I want.
Update 2/20/13
One of the problems with getting a link from Gruber is that a post written with my usual audience in mind—people who generally know the shell better than I do—suddenly gets exposed to people who aren’t as comfortable with OS X’s Unix underpinnings.
Some of the recent commenters have had trouble: they either didn’t have a .bashrc (or .bash_profile) in their home directory or fixopenwith didn’t run after they added the alias to it. Explaining the purpose of these files isn’t something I want to do here, so I’ll just point to this page (thanks, phocean!) and this one and (take a deep breath before clicking and recognize that this doesn’t cover OS X) this one . To oversimplify a bit, one or both of these files act like a shell script that gets run whenever you launch the Terminal or add a new window or tab when Terminal is running (if you use iTerm instead of Terminal, I assume you know all about this).
What’s significant, and what’s missing from the explanation above, is that simply saving these files after adding the definition of fixopenwith won’t put that new definition into your running shell. You have to either open a new window/tab or run source ~/.bashrc first. Hope this helps.




February 16th, 2013 at 10:47 pm
My
~/bin/directory is filled with scripts where I learned a neat hint or fix somewhere, and I wanted to save it in case I need it in the future.February 17th, 2013 at 7:16 am
Perfect timing, Doc. I just found out that the trick I had for fixing the ‘Open With’ menu (something to do with deleting
~/Preferences/LaunchServices.plist) didn’t work anymore—come to think of it, I’m not sure it ever worked at all.Anyway, this did require a
killall Finderfor me on Mountain Lion. I’m a bit wary of putting&& killall Finderin the alias though, because I think there ought to be a more elegant way to force the Finder to refresh its cache than killing it.On a somewhat unrelated note: Did you stop using Skim as the default app for PDFs? I’ve gone back and forth between Skim and Preview in the past few months. I really can’t choose between full screen mode and SyncTex support…
February 17th, 2013 at 9:53 am
I finally got around to fixing this the other day too. I noticed that the apps that were being duplicated there in my case were all from the App store. I assumed dupes were being created every time I updated those apps.
February 17th, 2013 at 2:39 pm
Worked, thanks! The only issue I noticed after running it and relaunching Finder was that anything menu or application that interacted with Finder was not responding (Show in Finder), so a reboot fixed that.
February 17th, 2013 at 4:21 pm
Arjan, I went back to Preview as my default PDF viewer when I got my new iMac. I’ve always preferred Preview, but it ran very poorly on a memory-constrained machine under Lion, so Skim made sense. Now that I have more breathing room, Skim isn’t necessary.
February 17th, 2013 at 4:40 pm
Worked perfectly. For first timers, you can use Pico to easily edit your .bashrc or .profile file. In terminal type pico ~/.profile and then paste the instruction in.
February 18th, 2013 at 12:40 am
So THAT’S how to fix that! Many thanks.
February 19th, 2013 at 5:34 am
To add to David’s tip: if you do
chmod -x .profileyou can justopen .profilein TextEdit or whatever your default text editor is.February 19th, 2013 at 2:36 pm
I don’t see the value in making
.profileexecutable. You can open it in any text editor regardless of the setting of the executable bit.February 19th, 2013 at 6:25 pm
Weird, and I’m sure this is a total coincidence, but I read the exact same tip on Cult of Mac a few days ago, and OSXDaily last month. Even the use of a bash alias with the suggested name of ‘fixopenwith’ is the same.
February 19th, 2013 at 6:35 pm
Thanks for the link to my question! But I didn’t post it on Stack Overflow…
February 19th, 2013 at 7:06 pm
If you use TextExpander (or similar), you can add…
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user && killall Finder
…to your snippet library and do both commands at once.
February 19th, 2013 at 7:45 pm
Is OSX 10.8.2 the file you have to paste this into is called
.bash_profile.I forget how you view hidden files on OSX 10.8.2 since I always have it on, but once you can view hidden files you can just go to your user directory and paste it in the file with your favorite text editor. (Note: You may have to make the file.)
I didn’t have to
killall Finder, though.February 19th, 2013 at 8:26 pm
Fishrock,
There are rules that distinguish when
.bashrcis sourced and when.bash_profileis sourced. I probably should have mentioned that to avoid confusing myself, I put everything in.bashrcand have.bash_profilesource it.February 19th, 2013 at 8:49 pm
Only works on 10.5 and later.
Anyone have a suggestion for Tiger?
February 19th, 2013 at 8:49 pm
This worked. Thanks. The only app that was showing up multiple times was Opera, but I had six of them in my list.
February 19th, 2013 at 8:59 pm
This problem with duplicate entries in the Open With menu is known to Apple, and filed as Bug ID# 11582257. I found this out when I reported the problem to Apple Bug Reporter myself and they told me it was an existing bug they were already tracking.
February 19th, 2013 at 9:32 pm
TinkerTool System (a great utility) has the ability to invoke this function that rebuilds the LS database. By far the easiest way for people who don’t want to bother with Terminal.
February 19th, 2013 at 10:04 pm
I created an Automator workflow to do this, saved it as an application, and set it up to run every time I log in. I don’t have to worry about this problem anymore; give it a try.
February 19th, 2013 at 10:22 pm
I don’t have a suggestion, jsk, but I’m surprised it doesn’t work with Tiger. This hint goes back to 2004, which is before Tiger. Maybe the path to
lsregisteris different on your machine?February 19th, 2013 at 11:04 pm
Thank you! My “Open With” had a half-dozen entries for some apps. Now, any idea how to solve that thing where OSX renders some icons in low-res? (Maddening, seemingly unfixable)
February 20th, 2013 at 1:41 am
jsk, I have note from a few years ago of a similar fix, but with a different path to lsregister:
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain system -domain user
Might be worth a try?
February 20th, 2013 at 4:35 am
Novice here. I think I edited my .profile file and .bashrc file to the instruction given. What have I actually done? Are these important files that should contain certain information? It had the desired effect - my duplicates seem to be gone (along with some application options altogether - but they seem to come back once I select “Other” and choose the app.)
February 20th, 2013 at 4:57 am
No time to investigate exactly why at the moment, but this lsregister command with the suggested flags caused my copy of the (public beta) BlueStacks App Player - an Android OS emulator - to spontaneously uninstall itself.
Strange.
February 20th, 2013 at 5:03 am
Dr. Drang: “chmod -x” will remove the exec flag, not set it.
February 20th, 2013 at 7:33 am
Exactly Bert. If the executable bit is set, the file will open in Terminal by default. Not so great for editing.
February 20th, 2013 at 8:35 am
Novice here, running 10.8.2
In my user folder I have .bash_history and .barrage_hscr
If I try to create a .bach_profile with the proper code and run fixopenwith in the Terminal, the Terminal hangs and the command is never completed. Surely, I’m missing something. Any suggestions? Thanks.
February 20th, 2013 at 9:11 am
I wonder if this has anything to do with my “Open With” being incredibly slow to respond when I mouse over.
It takes up to 10 seconds to fly out from the menu after I mouse over it.
February 20th, 2013 at 9:31 am
If your ~/.bashrc file does not exist then just create it. You also need to make sure the following code is in your ~/.bash_profile file to make sure it gets sourced properly upon each login:
if [ -f ~/.bashrc ] then source ~/.bashrc fi
February 20th, 2013 at 9:34 am
Oops, let’s try that again. Perhaps I can get the Markdown to work this time…
February 20th, 2013 at 11:26 am
Thanks, I had about 5 context menus of some apps, and multiples on others. WTF! This fixed it.
February 20th, 2013 at 12:41 pm
I’ve tried a couple of things. I don’t seem to have a .bash_profile or .bashrc in my home directory. I created them and saved them using vi, but whenever I try to run the alias, it tells me “Command not found”.
I’ve created alias before on my university’s Ubuntu machines since we use Linux a lot for our programs, but haven’t messed around with Mac OS X alias’ too much.
February 20th, 2013 at 12:44 pm
Thanks for this great tip !!!
Regarding the .bashrc vs .bash_profile debate, Mac OS is the exception to the rule: http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html
So there is no reason to create .bashrc, as .bash_profile will be call anytime you open a terminal window. And anyway, who is going to change aliases all the time: .bash_profile would be enough most of time.
You only need to source the newly edited file to get the command recognized: source .bash_profile
February 20th, 2013 at 1:04 pm
Thanks for the great tip. I was really sick of seeing 5 versions of BBEdit, 4 versions of Photoshop, etc., in the menu.
February 20th, 2013 at 1:40 pm
Thank you so much! Just needed to reopen Finder’s window after the execution.
February 20th, 2013 at 1:54 pm
Thank you thank you thank you. I have lived with 3 BBEdit’s for quite a while and now it’s fixed.
Instead of editing my profile I pasted your code in a ~/bin/fixopenwith file, added the url of this page as a comment and did chmod 700.
There was a time when OS X was smart in a pleasantly unobtrusive way and fixed these things before you even noticed.
February 20th, 2013 at 2:58 pm
Bert and Arjan,
Oh crap, you’re right. How embarrassing. Now that I think of it, I wonder if I’ve ever used
chmod -x—it’s always beenchmod +xto make a script I’ve just written executable. I didn’t look carefully at what Arjan was doing.Also, my
.bashrcor.bash_profilehave never been executable. Is that common?February 20th, 2013 at 5:27 pm
Convenient timing for me. I was just specifying Xcode 4.5.2 rather than 4.6 as the default for opening Xcode projects, and noticed a zillion duplicates. The “Open With” menu looks much nicer now.
February 20th, 2013 at 6:52 pm
Had the same problem with multiple PDFPen iterations, did a boot into Single User mode and it got rid of all but one of the duplicates.
February 21st, 2013 at 10:45 am
Thanks for the tip! It fixed my open-with.
I haven’t quite figured out how to use ‘bbedit’ at the command-line, but CDing to /etc and running ‘sudo nano bashrc’ allowed me to append your fix to the end of the existing file.
Readers, don’t forget to open a NEW Terminal window after editing your .bashrc file.
February 21st, 2013 at 11:31 am
Nice tip!
Thanks a lot.
S.
February 21st, 2013 at 3:48 pm
Doc, I’d guess that you created
.bashrcand.bash_profileyourself, and that the default mask (permissions) for user-created files is different from that for system-created files. User-created files are non-executable by default, that’s why you need tochmod +xscripts.February 22nd, 2013 at 7:41 am
Thanks so much, Dr. Drang! For the not-so-geeky people like myself, I’ve just posted a downloadable macro for Keyboard Maestro that does the same thing. It’s configured to run at 5:30am each morning (but you can change that).
http://www.dafacto.com/2013/02/22/getting-rid-of-those-annoying-open-with-duplicates/
February 22nd, 2013 at 12:26 pm
Thank you for the updated post, as well as the original entry. I like to think that I’m an accomplished Mac guy, but I was unaware of setting the source to the active shell.
February 22nd, 2013 at 5:33 pm
If you are not comfortable with the Terminal shell and bash files, take a look at my blog post regarding this issue. I’ve detailed how to do this via an Automator script which is called from the Finder Services menu. Now you don’t need to bother with the shell in order to clean the Open With menu.
http://www.insomniacsoftware.com/?p=61
I hope this helps.
February 23rd, 2013 at 8:34 am
Thanks for that tip, fixed it right up! No Finder relaunch was required.
February 23rd, 2013 at 1:41 pm
Thank you!! This has been bothering me for months, so glad to have it resolved :P Thanks again.
February 24th, 2013 at 7:44 am
Thanks — I’ve used a utility to do this in the past and perhaps I’ll use your alias.
But… Aware that I sound like a curmudgeon. Wouldn’t we guess that Apple could take care of this glaring bug in an update? And there have been updates since I first had this problem. Uhh… somehow… super difficult for Apple to fix this?
February 27th, 2013 at 1:23 am
Is bash really the default shell on OS X? I could’ve sworn it was zsh, at least since they came to their senses back in 10.1 or 10.2 and stopped making it tosh. I’ve always been a zsh guy on Macs, anyway….
February 27th, 2013 at 1:24 am
tcsh*
(damn you, autocorrect!)
March 1st, 2013 at 6:42 am
Interesting: I have found the duplicates in Finder but none of them in PathFinder!
March 14th, 2013 at 10:23 am
Hello! I really like this blog. Tell me please - from where do you have information for ths post?
March 14th, 2013 at 12:35 pm
vps,
I found the
lsregisterinformation at the links given in the third paragraph.