regularfry
regularfry

Reputation: 3268

OS X: Testing presence of an app from the command line with open

I want to test whether Foo.app exists before I call:

$ open -a Foo.app bar

What search path does open use to look for Foo.app? I know it must include /Applications, which means it's not $PATH.

Upvotes: 1

Views: 73

Answers (1)

djromero
djromero

Reputation: 19641

I'd search it using mdfind and then use the obtained path (if any) to open it:


    # use head to pick the first one, replace with your favorite algorithm
    FOOPATH=`mdfind "kMDItemContentTypeTree == 'com.apple.application-bundle'wc 
             && kMDItemDisplayName == 'Foo'wc" | head -n 1`
    if [ -d $FOOPATH ]; then
        open $FOOPATH
    else
        echo Opps
    fi

Upvotes: 1

Related Questions