Skip to content
Menu

Remove a Mac App and Everything It Left Behind

Removes a Mac app and leftover files by exact name or bundle ID. It refuses Apple apps and apps with protected agent bundle IDs. A dry run until approved.

Remove a Mac app and everything it left behind is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Remove a Mac app and everything it left behind. Tell other MSPs how it worked for you.

Write a Review

LanguageBash
Runs onmacOS 13+; runs as root
Needsbash 3.2, root; Full Disk Access for the RMM agent to clear some protected folders
Changes thingsChanges what it runs on

What It Does

This script is a dry run until you set DRY_RUN=false and APPROVE=uninstall-mac-app, and it refuses to make more than 25 changes in one run unless you raise MAX_CHANGES. It needs root.

It finds the app bundle by exact name or exact bundle ID in /Applications and each user's Applications folder. APP is required and has no wildcards. If no bundle is found and you gave a bundle ID, it can still remove files matching that ID. It then removes the bundle, the launchd jobs (LaunchAgents and LaunchDaemons, in /Library and in each user's Library) whose program points into the bundle, and per-user and system leftovers in known folders derived from the bundle ID: Application Support, Caches, HTTPStorages, WebKit, Containers, Application Scripts, Saved Application State, Logs, the Preferences file and its ByHost copies, and the Application Support folder named after the app. For apps under /Applications, it also forgets package receipts that list the bundle itself. TARGET_USER restricts the per-user search to that user. System-wide paths are still checked.

The list of removed paths and each removed launchd plist are saved to the backup folder first. A running app is left alone, and the run ends SKIPPED, unless QUIT_APP is true, which asks the app to quit and then ends its processes.

It refuses Apple apps (com.apple.* bundle IDs or anything in /System) and names with wildcards. It refuses installed bundles with these protected agent prefixes: com.ninjarmm., com.jamf., com.jamfsoftware., io.kandji., com.addigy. and com.splashtop. Check any other agent yourself. If no bundle is found, cleanup by ID can still remove matching files for a non-Apple ID. If macOS refuses to delete a protected folder, grant the RMM agent Full Disk Access.

Before You Run It

  • Run it as a dry run first and read the list of every path it would remove.
  • Use the exact app name or bundle ID. Zoom matches Zoom.app, and us.zoom.xos matches its bundle ID.
  • Back up anything the user keeps in the app's containers, if they may want it. Deleted leftovers are not recovered by this script.
  • Tell the user before you set QUIT_APP to true. The app is quit, and unsaved work in it is lost.
  • Grant the RMM agent Full Disk Access, or macOS refuses to delete protected folders and the run ends in ERROR.

Type and Risk

  • Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
  • Risk: High. It is a dry run unless you set both DRY_RUN=false and APPROVE=uninstall-mac-app, and it stops before making more than 25 changes in one run unless you raise MAX_CHANGES. Run it once as a dry run and read the list first.
  • What it changes: Deletes the app bundle, its launchd jobs, per-user and system leftover folders and preference files, and package receipts.
  • Restart: It never restarts the machine.
  • Typical run: Under 1 minute.
  • Example answer: "Removed Widget (com.example.widget): the app and 7 related item(s)"
  • Tested before listing on macOS 27 (Apple silicon VM) with /bin/bash 3.2, run as root, against its own test cases.

Inputs

Pass an input as an argument (--input-name value), as an environment variable named as listed, which is how most RMMs pass script variables, or change its default in the DEFAULT_ lines near the top of the script. An argument wins over an environment variable, which wins over the default.

  • APP: REQUIRED. App name (Zoom for Zoom.app) or bundle ID, exact.
  • QUIT_APP: Quit the app first if it is running. Default false.
  • TARGET_USER: Only this user's leftovers. Default every user.

Every script also takes DRY_RUN, OUTPUT_FORMAT (Text, Answer, Json or Csv), EXPORT_PATH and RESULT_FIELD, which writes the answer to an RMM custom field, unless the list above words one differently.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

uninstall-mac-app.sh · 801 lines · 35.6 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.