How to enable single window mode in Safari

After browsing for a few hours in Safari it's possible to end up with a dozen windows or so because of links that open a new window (links with target="_blank"). I've always wished there was a way to have these links open in a new tab instead of a new window (sometimes referred to as single window mode).

In the latest Safari 3.1 Apple finally added a (hidden) preference! To enable single window mode and have all links open in a new tab that would normally have opened in a new window, we only need to enable the TargetedClicksCreateTabs preference using the following command (paste it into Terminal):

defaults write TargetedClicksCreateTabs -bool true

You might need to restart Safari before the setting is taken into effect. To disable the setting again, run the same command with false instead of true.

Have fun!

Update: thanks TUAW!

Update 2: check out my comment near the bottom for a possible way to do this on Windows. Update 3: I don't think The preference is not recognized in Safari for Windows.

Update 4: this setting does not appear to work in the Safari 4 Developer Preview.

Update 5: and it appears to be working again in the Safari 4 Developer Preview released on August 22nd!

Update 6: someone has been kind enough to point out that Safari 5.1 now has a user-facing preference that does this.