Category filter

Script to uninstall apps on Mac

On Macs, users typically delete apps by navigating to the Applications folder and selecting Move to Trash from the app’s context menu. The primary motive for uninstalling apps is often to free up storage space. However, this manual method may leave behind residual app files, occupying unwanted space on the system.

In organizational settings, managing apps across multiple devices can be a challenge. For instance, if a malicious app is discovered on several devices, IT admins must uninstall it simultaneously from all affected devices. Similarly, after an app’s testing phase, if it needs to be removed, IT admins would have to uninstall it from each device.

In such cases, they can utilize Hexnode’s Execute Custom Script action to run the script given below to uninstall the required apps from macOS devices.

Scripting language – Bash

File extension – .sh

Disclaimer:


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

Uninstall an app

Example – sudo rm –rf /Applications/Opera.app

The rm command removes the directory entries on a Mac. Some of the options supported with the command in this respect are –

-r : Removes the file hierarchy.

-f : Removes the files without prompting for confirmation.

This command can be used to remove applications on Mac as applications are also a form of file.

What happens at the device end?

The script uninstalls the application on the macOS device without any manual intervention. In addition, it clears the cache files associated with the application.

Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • The script is effective only if the application is already installed on the targeted devices. In cases where the application is not present, the script will be deployed without causing any changes on the device end.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository