OSX - How to auto Close Terminal window after the “exit” command executed.

前端 未结 14 1169
孤独总比滥情好
孤独总比滥情好 2020-12-12 16:02

When I\'m done with Terminal, I want to exit it. Right now, I have three options:

  1. killall Terminal. It will end the process, but rather abruptly. I don\'t t

相关标签:
14条回答
  • 2020-12-12 16:25

    How about the good old Command-Q?

    0 讨论(0)
  • 2020-12-12 16:25

    Actually, you should set a config on your Terminal, when your Terminal is up press +, then you will see below screen:

    Then press shell tab and you will see below screen:

    Now select Close if the shell exited cleanly for When the shell exits.

    By the above config each time with exit command the Terminal will close but won't quit.

    0 讨论(0)
  • 2020-12-12 16:26

    In the Terminal app, Preference >> Profiles tab.

    Select the Shell tab on the right.

    You can choose Never Ask before closing to suppress the warning.

    0 讨论(0)
  • osascript -e "tell application \"System Events\" to keystroke \"w\" using command down"

    This simulates a CMD + w keypress.

    If you want Terminal to quit completely you can use: osascript -e "tell application \"System Events\" to keystroke \"q\" using command down"

    This doesn't give any errors and makes the Terminal stop cleanly.

    0 讨论(0)
  • 2020-12-12 16:29

    I tried several variations of the answers here. No matter what I try, I can always find a use case where the user is prompted to close Terminal.

    Since my script is a simple (drutil -drive 2 tray open -- to open a specific DVD drive), the user does not need to see the Terminal window while the script runs.

    My solution was to turn the script into an app, which runs the script without displaying a Terminal window. The added benefit is that any terminal windows that are already open stay open, and if none are open, then Terminal doesn't stay resident after the script ends. It doesn't seem to launch Terminal at all to run the bash script.

    I followed these instructions to turn my script into an app: https://superuser.com/a/1354541/162011

    0 讨论(0)
  • 2020-12-12 16:32

    Create a script:

    cat ~/exit.scpt

    like this:

    • Note: If there is only one window, just quit the application, else simulate command + w to close the tab)

    tell application "Terminal" set WindowNum to get window count if WindowNum = 1 then quit else tell application "System Events" to keystroke "w" using command down end if end tell

    Then add a alias in your *shrc

    just like vi ~/.bashrc or zshrc (anything else?)

    add it: alias exit="osascript ~/exit.scpt"

    And source the ~/.bashrc or reopen your terminal.app

    0 讨论(0)
提交回复
热议问题