{"id":241,"date":"2011-05-26T10:13:01","date_gmt":"2011-05-26T16:13:01","guid":{"rendered":"http:\/\/mattdturner.com\/wordpress\/?p=241"},"modified":"2011-05-26T10:14:24","modified_gmt":"2011-05-26T16:14:24","slug":"mac-os-x-quit-application-from-command-line","status":"publish","type":"post","link":"https:\/\/mattdturner.com\/wordpress\/2011\/05\/mac-os-x-quit-application-from-command-line\/","title":{"rendered":"Mac OS X Quit Application from Command Line"},"content":{"rendered":"<p><a href=\"http:\/\/mattdturner.com\/wordpress\/wp-content\/uploads\/2011\/05\/close.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-249\" title=\"close\" src=\"http:\/\/mattdturner.com\/wordpress\/wp-content\/uploads\/2011\/05\/close.png\" alt=\"\" width=\"256\" height=\"256\" srcset=\"https:\/\/mattdturner.com\/wordpress\/wp-content\/uploads\/2011\/05\/close.png 256w, https:\/\/mattdturner.com\/wordpress\/wp-content\/uploads\/2011\/05\/close-150x150.png 150w, https:\/\/mattdturner.com\/wordpress\/wp-content\/uploads\/2011\/05\/close-144x144.png 144w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a>When doing any type of programming or scripting, I do my best to streamline everything (see <a href=\"http:\/\/mattdturner.com\/wordpress\/2011\/04\/automatically-make-shell-scripts-executable\/\">this post<\/a> and\u00a0<a href=\"http:\/\/mattdturner.com\/wordpress\/2011\/05\/using-linux-expect-to-automate-interactive-processes\/\">this post<\/a>). \u00a0Basically anything I do in the Terminal that can be automated, I try to automate. \u00a0In addition to the posts linked above, I also have macros set up to login me into the supercomputer that I do most of my research on.<\/p>\n<p>When I first open Terminal, I have it set to open 4 Terminal windows in specified locations. \u00a0For those of you who don&#8217;t know how to do this, I will soon be providing a post detailing the necessary steps to accomplish this.<\/p>\n<p><!--more-->I also have a macro set to log me off of the supercomputer in each Terminal window and close the Terminal windows. \u00a0But, that still leaves me with the task of actually quitting the Terminal application. \u00a0Many of you may think &#8220;who cares if you have to hit command+q&#8221;. \u00a0Well, as I mentioned previously, I like to automate as much as possible.<\/p>\n<p>I was able to find a bash script that can quit any running application from the Terminal. \u00a0This is easily accomplished using the <em>kill<\/em> command, however the kill command will not save any work that is currently open. \u00a0This <em>quit<\/em> script uses osascript:<\/p>\n<pre class=\"brush: plain; light: true; title: ; notranslate\" title=\"\">Quit is an executable bash script to make it quick and easy\r\nto politely quit applications from the command line.\r\n\r\nThis script takes one or more application names as\r\narguments, and uses osascript to tell each one to quit.\r\nUnlike kill and killall, this allows applications to save files\r\nand perform any necessary operations before exiting.<\/pre>\n<p>The script can be found at <a href=\"http:\/\/web.me.com\/jonstovell\/personal\/Software.html\" class=\"broken_link\">Jon Stovell&#8217;s site<\/a>, or on <a href=\"http:\/\/www.macupdate.com\/app\/mac\/31821\/quit\">macupdate<\/a>.<\/p>\n<p>There have been a few modifications to the script by some of the users, and the modifications have been posted in the comments section of the MacUpdate website. \u00a0I have added a few of these modifications to the script, and you can download the <a href=\"http:\/\/mattdturner.com\/resources\/quit\">modified version here<\/a>.<\/p>\n<p>For instructions on how to use the script, just run it.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">Usage: quit [-a] [-p] [-s|n] [-f] &lt;application names&gt;\r\n\r\nArguments are the names of one or more applications.\r\nArguments are not case sensitive.\r\nArguments with spaces should be quoted.\r\n\r\nOptions:\r\n-a\tMatch argument string with any of the application's\r\n\t\tname, displayed name, short name, or title.\r\n\t\tE.g.: `quit &quot;microsoft word&quot;` and `quit -a word`\r\n\t\twill both quit Microsoft Word, because the app calls\r\n\t\titself &quot;Word&quot; in the menu bar.\r\n-p\tUse partial matches (e.g. edit for TextEdit). Prompts\r\n\t\tfor confirmation.\r\n-s\tAttempt to save modified files when quitting.\r\n\t\tOverrides any previous -n option.\r\n-n\tDo not attempt to save modified files when quitting.\r\n\t\tOverrides any previous -s option.\r\n-f\tDo not print an error message if app is not running\r\n\r\nIf neither the -s or -n options are specified, quit will try\r\nto detemine if any documents require saving, and if necessary\r\nwill ask the user whether to save or not.<\/pre>\n<h6 class=\"zemanta-related-title\" style=\"font-size: 1em;\">Related articles<\/h6>\n<ul class=\"zemanta-article-ul\">\n<li class=\"zemanta-article-ul-li\"><a href=\"http:\/\/hints.macworld.com\/article.php?story=20090815113819149\" class=\"broken_link\">Quit applications politely from command line<\/a><\/li>\n<\/ul>\n<div class=\"zemanta-pixie\" style=\"margin-top: 10px; height: 15px;\"><a class=\"zemanta-pixie-a\" title=\"Enhanced by Zemanta\" href=\"http:\/\/www.zemanta.com\/\"><img decoding=\"async\" class=\"zemanta-pixie-img\" style=\"border: none; float: right;\" src=\"http:\/\/img.zemanta.com\/zemified_e.png?x-id=c9c68221-c30e-4ee8-bedf-040e8b468353\" alt=\"Enhanced by Zemanta\" \/><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>When doing any type of programming or scripting, I do my best to streamline everything (see this post and\u00a0this post). \u00a0Basically anything I do in the Terminal that can be automated, I try to automate. \u00a0In addition to the posts linked above, I also have macros set up to login me into the supercomputer that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":249,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3,11,20],"tags":[17,162,167,62,164,165,69,14,163,166,25,161,160],"class_list":["post-241","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-command-line","category-mac","category-scripting","tag-apple","tag-bash","tag-close-application","tag-command-line-interface","tag-kill","tag-kill-all","tag-mac-2","tag-mac-os-x","tag-quit","tag-quit-application","tag-script","tag-terminal","tag-terminal-emulator"],"_links":{"self":[{"href":"https:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts\/241"}],"collection":[{"href":"https:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/comments?post=241"}],"version-history":[{"count":8,"href":"https:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts\/241\/revisions"}],"predecessor-version":[{"id":251,"href":"https:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts\/241\/revisions\/251"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/media\/249"}],"wp:attachment":[{"href":"https:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/media?parent=241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/categories?post=241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/tags?post=241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}