I want to edit a part of an Apple Script to quit various applications at once:

tell application "TweetDeck"
end tell
tell application "Google Chrome"
end tell

Over all there are seven entries just like above.

Is there any way to write this more compact?


You can use a list of apps and a loop. Just add new apps to that first list and they'll be quit automatically.

set apps to {"Google Chrome", "Tweetbot", "ForkLift"}
repeat with thisApp in apps
    tell application thisApp to quit
end repeat
  • Yay, this is very much what I wanted to have! – gentmatt Oct 24 '12 at 15:30
tell application "TweetDeck" to quit
tell application "Google Chrome" to quit

tell-end-tell blocks with only one command can be written in one line.


Unfortunately you cannot pass multiple applications to the 'tell application' call.

Rather, you could use a unix utility that can terminate multiple applications at once - killall.

You can invoke this utility from within an AppleScript:

do shell script "killall firefox Mail" - This would terminate FireFox and Mail

'killall' is case sensitive, so you must first determine the process names of the applications that you wish to kill.

  • Launch the applications that you will want to be terminating with the script
  • Use the following command (in a Terminal window) to find their full and correct names. (In this example, we are looking to find out tweetdeck's correct process name).

ps x | grep -i tweetdeck | grep -v grep

With TweetDeck running, this will give output similar to the following:

59127 ?? S 0:01.23 /Applications/TweetDeck.app/Contents/MacOS/TweetDeck -psn_0_21423213

The last part of the path is the process name as it should be passed to 'killall'. In this case TweetDeck (...Contents/MacOS/TweetDeck).

So, we go back to our AppleScript and add TweetDeck to the string of applications that we are terminating. In addition to my previous example, I'd do:

do shell script "killall firefox Mail TweetDeck"

Hope this helps!

  • Thanks for this detailed answer! I guess this trick could work just fine. Then I could also use a stronger command to make sure that applications are quit. – gentmatt Oct 24 '12 at 14:13
  • 1
    killall is such a command. So far in my testing it terminates and "takes no prisoners". You could also look into using kill -9 instead of killall. – macaco Oct 24 '12 at 14:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .