MacOS – Close window without closing application

keyboardmacos

How to close a window without the application quitting? does not address my question, strangely. I don't want to hide the application windows like Cmd+h does, and Option+click didn't actually do anything for me, and isn't what I want anyway.

I work with a lot of different application windows, especially with the browser and the terminal (I'm a software engineer and run my coding editor, debuggers, servers, etc. from the terminal and am constantly switching between term windows and tmux sessions to develop/troubleshoot our solutions). Sometimes (actually, most of the time), when I finish with a session, I want to close the window without closing the application. I make heavy use of keyboard shortcuts, so it interrupts my flow to have to grab for the mouse and point->click the corner to close the window.

Is there a way to get a shortcut to close windows in OS X without closing the entire application? This is really interrupting my flow and productivity.

I'm using Mavricks, btw. I've also tried iTerm2 and the default Mac Terminal but couldn't find anything that lets me do this in either of those applications. Chrome also doesn't seem to support closing just a Window. Either terminal is fine, I have things configured to the point where tmux eliminates my need for a fancy terminal, because Tmux can do it anyway, plus some.

Best Answer

Have you thought for a keyboard combination like cmd+w?

In Google Chrome you can close all tabs with cmd+shift+w, in Safari the same way.

Alternatively you can write an AppleScript like tell application "Terminal" to close front window or as terminal command: osascript -e 'tell app "Terminal" to close front window'.