0

I regularly run Python scripts from an iTerm2 command window, and the scripts usually generate several plots. I have an IDE open as well.

From time to time I end up accidentally closing the iTerm window with a command-W instead of closing Python's matplotlib windows that I'm targeting.

If I've had too much coffee I may end up doing this a few times in an afternoon.

I don't see any useful function that closing an iTerm2 window with command-W would ever serve me, so I'd like to inhibit it's closing power on iTerm2.

Under iTerm2/Preferences/Closing I see some options to require confirmation upon command-Q, but there seems to be nothing that addresses command-W under any menu item.

Question: How can I stop command-W from closing iTerm2 when it's active instead of the Python plots I'm intending to close?

Alternatively, if there's a way to get the closed window back somehow (since it doesn't seem to be gone; if the script used a lot of memory it remains allocated even when the window is closed) that would certainly at least help.

iTerm2 preferences

uhoh
  • 1,718
  • Does this answer your question? Disable Command-W in the terminal - basically you just override the shortcut to be something else. – JBallin Oct 02 '22 at 22:06
  • 1
    Also related: https://apple.stackexchange.com/q/44412/151404 - I see a comment suggesting CMD+Z will restore the closed window in iterm. – JBallin Oct 02 '22 at 22:07
  • @JBallin yes it does, and I can't understand why it didn't display at the top when I was getting ready to post. Thanks! And thanks for the undo (CMD+Z) hint, which could have been a useful answer post to this question but not the duplicate. "Alternatively, if there's a way to get the closed window back somehow..." – uhoh Oct 02 '22 at 22:10
  • 1
    Glad it was helpful! I actually meant to also link this related question: https://apple.stackexchange.com/q/390234/151404 – JBallin Oct 02 '22 at 22:17
  • @JBallin This is the first time I've seen undo operate on a window closing, i.e. I've never seen "unclose" before! – uhoh Oct 02 '22 at 22:19
  • 1
    Agreed. Command Shift T would likely be more intuitive, like the browser shortcut. Btw I don't see a question for "how do I reopen a closed iterm tab" - if you're interested in creating & answering that as a separate question. – JBallin Oct 02 '22 at 22:22
  • @JBallin Oh, the comments under the answer show that now we must use "Close" and not "Close Window". https://i.stack.imgur.com/pSWRi.png – uhoh Oct 02 '22 at 22:34
  • You map shortcuts to whatever the action is named in the menu bar. – JBallin Oct 02 '22 at 23:11
  • @JBallin and need to use the name of the action in 2022 and not the name of the action in 2012 – uhoh Oct 02 '22 at 23:19
  • Your screenshot is for Terminal.app, not iTerm - the action names are set by each app. – JBallin Oct 03 '22 at 03:55
  • @JBallin I disagree. iTerm2 is the only command window I use, see this screenshot https://i.stack.imgur.com/BTHgG.jpg – uhoh Oct 03 '22 at 04:08

0 Answers0