Middle Click Close For Safari

08/31/2009 Update: For Snow Leopard compatibility, see here.

08/13/2009 Update: It should now work with all future versions of Safari without having to update it again. Read about the change here.

06/09/2009 Update: I have just updated the plugin distribution to work with the just-released production version of Safari 4. If you have problems with it, please let me know.

03/05/2009 Update: It’s working again.

02/27/2009 Update: This plugin is not working with the just-released Safari Beta 4. I know this. I will have to spend some time with the beta before I know why it broke. I will try to find time to take a whack at it this weekend.

I love Safari on my shiny Mac Pro, particularly because it’s so much faster than Firefox. But one thing I missed from Firefox was being able to do a middle-click on a tab and have it close. After several failed attempts, I finally got some help from Mark Rowe who pointed me to a proper method-swizzling implementation. After switching my code to use that swizzler, everything fell into place. I’ve been happily using it ever since, I just never released it. I got an email the other day asking for it, so here it is.

Unlike my Export to Archive plugin for iPhoto, I didn’t build an installer for this one. It’s easy to install, but you still have to do it yourself. And there’s a dependency: SIMBL. Now, before Leopard shipped the word was that Input Managers would no longer be supported. After Leopard shipped we saw that wasn’t entirely true. So, once you get SIMBL installed and working, using my plugin is easy. This should work on both Tiger and Leopard. I’ve only tested it recently on Leopard, but I originally wrote it on a Tiger system.

  1. Get the binary package: MiddleClickClose.zip
  2. Create ~/Library/Application Support/SIMBL/Plugins if it doesn’t exist
  3. Unzip the MiddleClickClose.zip into this directory. You should end up with a directory called MiddleClickClose.bundle
  4. Restart Safari

If all goes well, you should now be able to use your middle mouse button to close Safari tabs. It works for me. If it doesn’t work for you, run the OSX Console and look for “MiddleClickClose loaded” in the “Console Messages” section.

If you want the source code, download it here.

I should mention that this really is a dirty hack, and may not work with future versions of Leopard. It works for me, but your mileage may vary. I hope it works for you, but it may not.

This code is distributed under the GPL v2.

11 thoughts on “Middle Click Close For Safari

  1. Hi,
    I love MiddleClickClose, but since upgrading to Safari 3.1 it doesn’t work anymore..
    Are you planning on making it compatible?
    Kind regards,
    Lorenzo

  2. You are a legend! Thank you.
    Safari should have this along with the middle click on back button opens a new tab by default.
    Matt

  3. How do you install SIMBL, where do i get SIMBL from?
    sorry if this sounds like a silly question i’m new to this.

  4. Thanks, Jack. It’s a dirty, dirty hack, but until Apple builds this functionality into Safari, it’s all we have. I actually wonder if Apple will ever include something like this, since the Mac culture is so against multi-button mice.

  5. Love the plugin, but since I’ve installed it I’ve noticed more and more Safari hangups and crashes. It’s fairly infrequent but can be a bother.

Comments are closed.