How to find out if iTerm is installed on a mac from within a shell script?

Solution 1:

The open command will open it no matter where the person has it installed (you don’t have to put an app in /Applications on macOS).

open -a iTerm.app

You could search using spotlight as well

 mdfind "kMDItemCFBundleIdentifier == com.googlecode.iterm2"

Solution 2:

Assuming it's installed in the standard Applications folder, use

if [[ ! -d /Applications/iTerm.app ]]; then
    # proceed with installing iTerm
fi

If you want to cover for situations where iTerm isn't installed in the standard location, you might use

open -g -j -a iTerm 2>/dev/null
if [[ $? -eq 0 ]]; then
    sleep 3
    osascript -e 'tell application "iTerm" to quit'
else
    # install iTerm
fi

If iTerm is already running it will exit in this case.

Solution 3:

There are at least two places where iTerm.app might be found, either in the /Applications/ folder (99% of the time) or the user’s own $HOME/Applications/ folder (very rare, but possible).

You can check to see if it is in either of those places like so:

if [ ! -d '/Applications/iTerm.app' -a ! -d "$HOME/Applications/iTerm.app" ]
then

    echo 'iTerm is not installed'

fi

I’ll also mention that I already have a script that will download and install the latest version of iTerm:

https://github.com/tjluoma/di/blob/master/di-iterm.sh

which is part of my di - download & install repo, which will do this for 300+ Mac apps.

di-iterm.sh uses the official Sparkle / XML feed to check for the latest version, and there are ways to use the beta or nightly builds if you prefer one of those options.

If it is already installed and up-to-date, it will just report that information and exit.

If it is not installed or out-of-date, the script will download the latest version, install it, and move the old version to the trash.

If you have questions or problems, feel free to leave me an issue on GitHub or email me (my email is in the script). Please also feel free to use / adapt my script as a starting point if you want to do something different.