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

前端 未结 14 1171
孤独总比滥情好
孤独总比滥情好 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:33

    In a terminal window, you can type:

    kill -9 $(ps -p $PPID -o ppid=)
    

    This will kill the Terminal application process, which is the parent of the parent of the current process, as seen by the kill command.

    To close a Terminal window from within a running script, you need to go up one more level in the process hierarchy like this:

    kill -9 $(ps -p $(ps -p $PPID -o ppid=) -o ppid=) 
    
    0 讨论(0)
  • 2020-12-12 16:38

    You can also use this convoluted command, which does not trigger a warning about terminating its own process:
    osascript -e "do shell script \"osascript -e \\\"tell application \\\\\\\"Terminal\\\\\\\" to quit\\\" &> /dev/null &\""; exit

    This command is quite long, so you could define an alias (such as quit) in your bash profile:
    alias quit='osascript -e "do shell script \"osascript -e \\\"tell application \\\\\\\"Terminal\\\\\\\" to quit\\\" &> /dev/null &\""; exit'

    This would allow you to simply type quit into terminal without having to fiddle with any other settings.

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

    I've been using

    quit -n terminal

    at the end of my scripts. You have to have the terminal set to never prompt in preferences

    So Terminal > Preferences > Settings > Shell When the shell exits Close the window Prompt before closing Never

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

    If this is a Mac you type 'exit' then press return.

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

    in Terminal.app

    Preferences > Profiles > (Select a Profile) > Shell.

    on 'When the shell exits' chosen 'Close the window'

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

    You could use AppleScript through the osascript command:

    osascript -e 'tell application "Terminal" to quit'
    
    0 讨论(0)
提交回复
热议问题