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

#!/bin/sh

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

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?

link|improve this question

53% accept rate
feedback

2 Answers

up vote 3 down vote accepted

Use a function instead:

alias quit=_quit
function _quit
{
osascript <<EOF
tell application "$*"
  quit
end tell
EOF
}
link|improve this answer
tell application "$*" to quit is more compact. – Daniel Beck Dec 16 '10 at 2:02
feedback

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
        return
    fi
echo | osascript <<EOF
tell application "$1"
  quit
end tell
EOF
}

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.