Category filter

Script to get the app path of an application from macOS devices

For the deployment of application-specific scripts remotely or from a terminal, identifying the path to the application is a requirement. The app paths are also necessary while defining the list of allowed/blocked applications across endpoints. On macOS devices, the app path can be found by right-clicking on the application and selecting the “Get Info” option. In an organization that manages numerous devices, you can get the app path for the applications installed on the devices using custom scripts. IT admins can deploy the script to get the path to a specific application with the help of Hexnode UEM’s Execute Custom Script remote action.

Scripting language – Bash

File extension – .sh

Disclaimer:


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

Find app path

The mdfind command is an interface to the Spotlight search tool on macOS devices. It allows you to perform searches using the metadata index and fetch a list of files matching specific search criteria.

The kMDItemCFBundleIdentifier is a metadata attribute associated with files on macOS devices. This attribute helps uniquely identify app bundles.

When you replace “bundle ID” in the script with the actual bundle ID of an application, it retrieves the path of the app installed on a macOS device.

For example:
path=$(mdfindkMDItemCFBundleIdentifier="com.apple.Safari")
echo "The path to the application is:" $path

Here, the “bundleID” has been replaced with the bundle ID of the Safari app, which is “com.apple.Safari”. The given example script also uses the ‘mdfind’ command to locate the path of the Safari app that is already installed on the device by searching for the specified bundle identifier “com.apple.Safari”. Then, the identified path is assigned to a variable named ‘path’ whose value gets displayed.

What happens at the device end

Upon successful execution of the script, the application path for the specified app will be visible in the Action History tab of the Hexnode UEM portal. In the Safari app’s case, the retrieved path will be /Applications/Safari.app.

The action history tab in Hexnode UEM displays the retrieved path of the Safari app.

The bundle ID of the app can be obtained either from the Manage tab, Apps tab or directly from the device itself.

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