How can check if particular application/software is installed in Mac OS

Viewed 25609

I want to check if particular application is installed in Mac OS using Perl/Shell scripts. I am writing package using PackageMaker in which i need to check user machine for few applications before installing the application. So am planning to write a script that will check this for me. Please advice if I can perform this in better way.

5 Answers

You can use AppleScript to ask for the "ID" of the application. (But see the update below for a more reliable way!)

Here is an example that can be used in a Bash script to check if "QuickTime Player 7" is available:

if osascript -e 'id of application "QuickTime Player 7"' >/dev/null 2>&1; then
    echo "Yes, QT 7 is available"
else
    echo "No, QT 7 not found"
fi

The application name is not case-sensitive, so "quicktime player 7" also works.

If you want to use a Bash variable for the app name in your script, be aware that AppleScript requires double-quotes around the app name. So you would need to write something like this, escaping the double quotes:

app='QuickTime Player 7'
if osascript -e "id of application \"$app\"" >/dev/null 2>&1; then
   #...
fi

Update:

However, as I discovered with this particular example which I was using, the application name may change! On a different machine, the same QT 7 app was named "QuickTime 7 Pro" instead of "QuickTime Player 7".

So the more reliable solution is to know the ID of the application, which should remain the same across different installs. Then you can check for the existence of that ID.

if osascript -e 'exists application id "com.apple.quicktimeplayer"' >/dev/null 2>&1; then
    ((debug)) && echo "OK: Quicktime 7 found" >&2
else
    echo "ERROR: Cannot find Quicktime 7" >&2
fi
Related