Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I found the following shell script that can be used to tell an OS X application to quit:


echo | osascript <<EOF
tell application "$*"
end tell

I have several simple alias commands in my .bash_profile and would like to add a "quit" command there instead of using this script. I created the following, but it doesn't work:

alias quit='osascript -e "quit application \"$1\""' 

I'm sure I've munged the command. Any advice?

share|improve this question
up vote 6 down vote accepted

Use a function instead:

function quit {
osascript <<EOF
  tell application "$*" to quit
share|improve this answer
tell application "$*" to quit is more compact. – Daniel Beck Dec 16 '10 at 2:02
@DanielBeck: I've edited it to remove other redundancies as well, such as defining an alias whose only purpose is to call the function. I left the HEREDOC-style quoting as I was having problems with alternatives and grew impatient ;) – iconoclast Oct 4 '13 at 0:28

Aliases can't have parameters. Aliases do a strict text substitution, where 'parameters' would kind of end up at the end.

I'd do a function, which can have parameters.

function quit
    if [ $# -ne 0 ]; then
        echo "usage: quit _appname_" >&2
echo | osascript <<EOF
tell application "$1"
end tell

Sorry, but I can't test this and verify today (no Mac), but the idea would work as a function.

share|improve this answer

You must log in to answer this question.

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