Quit is an executable bash script to make it quick and easy to politely quit applications from the command line.
This script takes one or more application names as arguments, and uses osascript to tell each one to quit. Unlike kill and killall, this allows applications to save files and perform any necessary operations before exiting.
What's New
Version 1.7.1:
Minor bug fix: Unnecessary debugging messages are no longer displayed.
Thank you, Jon. Apple should have included this in Mac OS X. The 'open' command has been in since NeXTSTEP. Why not 'quit'?
Anyhow, I added an option '-f' which says to *not* print an error message if the requested app is not running. Following is the 'diff' output which shows the difference between Jon's original and mine. Users can add this option to the script using the 'patch' command on their Mac.
The script allows you to quit a GUI application remotely while optionally saving unsaved changes in open documents. While this sounds like a good idea, it should be used with caution. Over an SSH connection, you have no way of knowing the state of the document you're saving. Maybe, since you left the computer, your cat or your three-year-old has filled the document buffer with gibberish, which you're now going to save in place of the original.
A better plan would be never to leave open documents unsaved when getting up from the computer. Then you won't need this script. If you must quit an application remotely and you think it has unsaved changes, use Screen Sharing to view the document before saving it.
If you are able to accomplish your objectives using Screen Sharing, then by all means use that tool. It has been useful to me more times than I can count.
However, there are all manner of usage scenarios where Screen Sharing may be an unavailable, undesirable, unnecessary, or just plain inapplicable tool. This script is intended to make life easier in such scenarios.
The -n option was designed to help address the situation in which one needs to quit a document-based app which may have been subject to attack by feline interlopers. But thinking about your comments has given me the idea to add an option to allow saving to a new file. I'll see if I can put that into the next version.
"Bash script to politely quit applications using Terminal."
How do we find out which applications are currently using Terminal? And how do we know when an application uses Terminal? I'd like to know that before having a script quit any application that uses Terminal.
"Using Terminal" means you can quit applications from withing Terminal. Normally to quit, say for example TextEdit, you simply will type 'quit TextEdit' and it will quit it. It quits the same way as you do by typing 'Command-Q' (fixme) for GUI apps. For quitting terminal apps didn't try it yet, but I guess for terminal apps 'killall' and 'quit' are equivalent (in most cases, fixme).
This is good in theory, but in practice, Quit refuses to quit anything I've tried (on 10.4.11). Neither the -a or -p flags seems to have any effect - I consistently get:
43:166: execution error: System Events got an error: Can't make every application process whose name = "Adium" or short name = "Adium" or title = "Adium" or displayed name = "Adium" into type reference. (-1700)
No running application matches "Adium"
Please login or create a new MacUpdate Member account to use this feature
Watch Lists are available to MacUpdate Desktop Members Upgrade Now
Download and auto-install
using MacUpdate Desktop. Save
time moving folders and cleaning-up.
Quit is an executable bash script to make it quick and easy to politely quit applications from the command line.
This script takes one or more application names as arguments, and uses osascript to tell each one to quit. Unlike kill and killall, this allows applications to save files and perform any necessary operations before exiting.
-1
+4
Kankei71 reviewed on 17 Jul 2011
What about 'quit all'?
+16
Jerry Krinock reviewed on 26 Mar 2011
Anyhow, I added an option '-f' which says to *not* print an error message if the requested app is not running. Following is the 'diff' output which shows the difference between Jon's original and mine. Users can add this option to the script using the 'patch' command on their Mac.
Basic tutorial:
http://www.linuxtutorialblog.com/post/introduction-using-diff-and-patch-tutorial
Intermediate tutorial:
http://www.linuxtutorialblog.com/post/introduction-using-diff-and-patch-tutorial
Here's the patch text, created by diff. I hope that MacUpdate's system doesn't munge it up.
22a23,25
> #
> # This is Jon's version 1.3, with the -f option added by
> # Jerry Krinock, 20110325
27c30
< echo "Usage: `basename "$0"` [-a] [-p] [-s|n] "
---
> echo "Usage: `basename "$0"` [-a] [-p] [-s|n] [-f] "
44a48
> echo " -f Do not print an error message if app is not running"
166c170,171
< while getopts "apns" opt
---
> ignoreNotRunning="false"
> while getopts "apnsf" opt
172a178
> f) ignoreNotRunning="true" ;;
206c212,215
< echo "No running application matches "$arg""
---
> if [[ $ignoreNotRunning == "false" ]]
> then
> echo "No running application matches "$arg""
> fi
-1
+115
A better plan would be never to leave open documents unsaved when getting up from the computer. Then you won't need this script. If you must quit an application remotely and you think it has unsaved changes, use Screen Sharing to view the document before saving it.
+2
+108
However, there are all manner of usage scenarios where Screen Sharing may be an unavailable, undesirable, unnecessary, or just plain inapplicable tool. This script is intended to make life easier in such scenarios.
The -n option was designed to help address the situation in which one needs to quit a document-based app which may have been subject to attack by feline interlopers. But thinking about your comments has given me the idea to add an option to allow saving to a new file. I'll see if I can put that into the next version.
+22
Ayub reviewed on 31 Aug 2009
-1
+16
"Bash script to politely quit applications using Terminal."
How do we find out which applications are currently using Terminal? And how do we know when an application uses Terminal? I'd like to know that before having a script quit any application that uses Terminal.
+1
+22
+14
jichi reviewed on 21 Jul 2009
BTW, I found this app by accidence. why not add this good stuff to MacPorts? Hence more people will know and use it and make it better and better.
+108
+17
+42
43:166: execution error: System Events got an error: Can't make every application process whose name = "Adium" or short name = "Adium" or title = "Adium" or displayed name = "Adium" into type reference. (-1700)
No running application matches "Adium"
+108