How can I make this Apple Script shorter? (quitting multiple apps via tell)

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

tell application "TweetDeck"
    quit
end tell
tell application "Google Chrome"
    quit
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

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!