Can I list installed applications from a Bash script? [closed]

When we image machines we install a list of applications.

At the end, we want to check that each has indeed been successfully installed.

In our shell script, how can we get a list of all installed applications so that we can compare it with our list of required apps?


Solution 1:

There are several ways via the command line to look to see if an Application is installed:

View the Applications Directory

  • To list all Applications installed system wide:

      $ ls /Applications                    
    
  • To list Applications installed by/for a specific user:

      $ ls /Users/<username>/Applications  
    

Query system_profiler

The following command will list every single Application installed on the system that's in the Applications database:

$ system_profiler SPApplicationsDataType

It lists everything including obscure apps/utilities installed by Apple (or 3rd parties) that was included with the macOS installation. Using grep we can limit it to a particular application.

$ system_profiler SPApplicationsDataType | grep -i Excel
    Microsoft Excel:
      Location: /Applications/Microsoft Excel.app

The caveat with these is that it must have been "properly" installed and registered with the system. If you happen to download a binary directly from a website (ffmpeg is an excellent example), it won't show up using any of these methods.

Use which or type

For binaries that weren't installed, but rather just downloaded or copied onto a system and assuming they are in the path, you can use the command which or type

$ which ffmpeg
/usr/local/bin/ffmpeg

$ type ffmpeg
ffmpeg is /usr/local/bin/ffmpeg