How do I quit the Terminal application without invoking a save dialog?

Hello, I am trying to write an AppleScript that will allow me to close the application Terminal without invoking a dialog box. In my situation I have just run a Python script on Terminal and when I try to quit the Terminal application I am always presented with a "Do you want to close this window?" dialog box. I wrote a simple AppleScript where I specify that I do not want to save when quitting but I am still presented with the dialog box. Does anybody know how to exit the Terminal application with an AppleScript that does not require any user interaction beyond initiating the AppleScript? Here is the simple script I wrote:

tell application "Terminal"
quit saving no
end tell

Thanks, George

MacBook Pro, Mac OS X (10.6.6)

Posted on Mar 3, 2011 9:37 AM

Reply
5 replies

Mar 3, 2011 10:08 AM in response to BioASys

The most obvious question is why you're using Terminal.app at all.

If your shell command doesn't require user interaction, then don't bother with the Terminal and have AppleScript run it directly, via do shell script rather than telling Terminal.app to run it.:

Bad:

tell application "Terminal.app"
do script "/path/to/blah -foo -bar"
end tell


Good:

do shell script "/path/to/blah -foo -bar"


Both have the exact same result (run the specified shell command), but the latter one doesn't launch Terminal.app, doesn't open any windows, and doesn't need any clean up after it completes.

Apr 7, 2011 9:36 AM in response to Hunter3740

The problem with blindly killing the terminal is that there may be ongoing shell processes running that will also terminate. Sure, from your script perspective, you know you opened one terminal window and that task has finished, but you don't necessarily know what other terminal/shell processes the user has running, or what they're doing, or whether they're safe to quit.

The right approach is to query Terminal.app to find out how many windows/shells are running, and what they're doing. Only if there are no (or maybe your one) windows open, or if all the windows are idle is the app safe to quit.

Using do shell script avoids all those issues. In fact it neither knows nor cares whether Terminal.app is running at all.

Apr 7, 2011 9:50 AM in response to Camelot

I agree with you: yours is a beautiful way. Just offering a quick and dirty way; e.g. if he's the only user, not running anything else, wants to double-tap his script file on his desktop and just have it run (see the results) and go away. Your issue with my quick and dirty is very valid for the common user (but he's using Python, so I'm sure he ignores warnings when running sudo, etc.).

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How do I quit the Terminal application without invoking a save dialog?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.