Stop Safari window closing when only pinned tabs are left

Love that Safari 9 has pinned tabs, it was the last piece that enabled me to switch from Chrome. However, I often close all tabs except the pinned tabs. However, unless I make one of the pinned tabs active and then close the other tabs it closes the whole window, pinned tabs and all.

For example, let's say I have one pinned tab and one not. If the unpinned tab is active and I hit command+w the whole window closes. But if I make the pinned tab active and then click the close button on the unpinned tab, the window stays open. Any way to keep the window open as long as there are any tabs open, pinned or otherwise?


If you watch the File menu, you can see W changes depending on the number of open tabs. If there are multiple, it's "Close Tab", if there is one (not counting the pinned), it's "Close Window".

There is a workaround! You can overwrite W to always execute "Close Tab".

Go to System Preferences > Keyboard > Shortcuts > App Shortcuts

Add a Shortcut for the application "Safari", menu item "Close Tab", shortcut w.

If you're not using English in Safari, lookup the exact name of the menu item for closing a tab. In the Dutch version of Safari, the menu item is called "Sluit tabblad".


Just want to add to hachre's answer that you can achieve the same result using terminal. For overwrite ⌘W in Safari execute following lines:

defaults write com.apple.Safari NSUserKeyEquivalents -dict-add 'Close Tab' '<string>@w</string></dict>'
defaults write com.apple.universalaccess com.apple.custommenu.apps -array-add '<string>com.apple.Safari</string>'

Then reload Safari:

killall Safari
open -a Safari

I use that commands in Sierra - works great.