macosxhints - Selectively closing multiple Safari windows and tabs: "OK, so this isn't a really complex tip, but it might be useful to somebody anyway. I'm sure we're all good experimental users, and we know that you can close all windows by pressing Command-Option-W in a window with no tabs (or one, if you have the tab bar always on), and that this becomes Close Other Tabs in a window with tabs. In a tabbed window, Close All Windows is then Command-Option-Shift-W. But what if you have a lot of windows, maybe with lots of tabs? And what if you want to close every window but one, similar to the Close Other Tabs feature? I tend to use Close Other Tabs a lot, often while Googling and looking at various results in many tabs. Often I also have many Google searches open in many windows at the same time, and I might want to pare it down to one window, but keep all its tabs intact, which is what this trick is aiming for.
The Dock comes to our rescue at this point: Close All Windows really means Close All (non-minimized) Windows. So, minimize any windows you want to keep open, and then press Command-Option-W or Command-Option-Shift-W, depending on whether you have multiple tabs in the frontmost window. Every open window gets closed, but the ones in the dock stay there until you need them.
A simple trick, but it might save you a few seconds from having to go through each window one by one and press Command-Shift-W or Command-W (again, as appropriate regarding the tab status of the window) to close them all."