Category filter

Script to get versions of installed apps on macOS

In this document, you will learn how to create and deploy a script to get the versions of apps installed on macOS devices.

The application version helps users, developers, and support teams identify and differentiate between various releases of the same software. Identifying the currently running version of the application ensures that the applications are running according to organizational requirements. Retrieving an application version can be easy when the devices are readily available to administrators. However, in situations where the devices are remote, it can be more challenging. For macOS devices, you can retrieve the application versions of the installed apps remotely using a custom script. IT administrators can use Hexnode’s Execute Custom Script remote action to deploy the following script to get versions of installed apps on macOS devices.

Scripting language – Bash

File extension – .sh

Disclaimer:


The sample scripts provided below are adapted from third-party open-source sites.

Retrieving the application versions

The following script uses the mdls command to print the values of all the metadata attributes related to the specified applications. Then the script retrieves the kMDItemVersion attribute using mdls command, where the application version is stored. The script retrieves a list of specified applications with their names and versions as output. If an application version cannot be retrieved, the script returns an error message: ‘Unable to retrieve version for the specific application.’

Before executing the script, make sure to replace Application1, Application2, and Application3 with the required application names. You can specify as many applications as needed. Replace Username with the account name of the user under which the specified applications are installed on the macOS device.

Upon successful script execution, the installed application versions will be retrieved and displayed in the Hexnode console. To view the output, navigate to the device details page by going to Manage > Devices and selecting your device. Then, click on Show Output for the corresponding action in the Action History tab.

Script to get versions of installed apps on macOS retrieves results to Hexnode console

Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository