Are uninstall routines ever run for normal macOS app removal?

If you "uninstall" an app from your Mac using the standard "uninstall" methodologies, does macOS ever run an uninstaller in the background to clean up files and/or folders outside the app's .app folder?

The standard "uninstall" methodologies that I know about are:

  1. trashing an application's .app folder, then emptying the trash
  2. long-clicking on an app in Launchpad, then clicking on its X while it jiggles

Are there any other standard methodologies to "uninstall" a macOS app?

Does any of the methodologies run any uninstall routine other than just deleting the .app folder from the file system (like maybe removing a folder under ~/Library/Caches)?

Are there any problems with running rm -rf <path-to-.app-folder> instead of trashing the app folder/Lauchpad jiggling to death the app?

Are there any differences between uninstall routines for apps installed from the Mac App Store versus apps installed by other means?

Answered by DTS Engineer in 809663022

macOS has a subsystem, Launch Services, that tries to keep track of which apps are installed and where. When you delete an app using standard user techniques, Launch Services updates its database, and that triggers a variety of actions. For example, it will unregister any app extensions contained within the app.

Additionally, the Finder understand whether an app has an active system extensions and will prompt to uninstall the system extension when you delete the app.

Are there any problems with running rm -rf <path-to-.app-folder> … ?

Yes. At a minimum, it can leave orphaned system extensions.

If you want to get rid of an app quickly, command-option-Delete is your friend.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

macOS has a subsystem, Launch Services, that tries to keep track of which apps are installed and where. When you delete an app using standard user techniques, Launch Services updates its database, and that triggers a variety of actions. For example, it will unregister any app extensions contained within the app.

Additionally, the Finder understand whether an app has an active system extensions and will prompt to uninstall the system extension when you delete the app.

Are there any problems with running rm -rf <path-to-.app-folder> … ?

Yes. At a minimum, it can leave orphaned system extensions.

If you want to get rid of an app quickly, command-option-Delete is your friend.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks for the info.

Does Launch Services update its database when you trash the app folder, or when you empty the app folder from the trash? (I assume the former)

If Launch Services updates upon trashing, how does Launch Services handle if the app is untrashed via the "Put Back" functionality from the context menu of items in the Trash in Finder? How does it handle if you just drag the app the app folder from Trash back to /Applications (or wherever it was originally located)? What if you drag the app folder from the Trash to some other folder?

I am working on a Swift command-line executable that allows for the uninstallation of apps installed from the Mac App Store.

i’ve seen 3 ways to trash items from Swift without starting a new Process:

  1. Workspace.shared.recycle(…)
  2. FileManager().trashItem(…)
  3. Sending AppleEvents to Finder to trash the item

Are there any other ways that might be better?

The last way includes "Put Back" in the context menus of the trashed items, while the first 2 seem to not include it in the context menus. The last way also follows the standard Finder renaming convention for when an item already exists in the Trash with the same base name as the app folder. The first two use a different renaming scheme than does Finder.

Which of these (or other) Swift-based trashing methods will work with Launch Services & any other things that notice app "uninstallations"?

Since these are apps from the Mac App Store, the app folders are owned by root. My executable thus requires being called as root via sudo (otherwise it couldn't trash the app folders). If the app folders are trashed while the user is root, however, they will be moved to root's Trash, not the user's Trash. To trash the app folders to the user's Trash, it changes the owner of the app folders being uninstalled to the running user (discovered from the $SUDO_USER environment variable), then setuids to that user, then trashes the app folder, then setuids back to root, then changes the owner of the trashed app folders back to root (because Mac App Store apps trashed via Finder remain owned by root in the user's Trash). Will that procedure cause any problems for Launch Services or other things that observe "uninstalls"? Is there any better way to do this?

Lastly, is there any way for Swift to empty from the user's Trash only the app folders that my executable just trashed? I don't want to empty all of the trash in case the user has other items in it.

Thanks.

Accepted Answer

IMO Apple events is your best option here. In that case the work will be done by the Finder and thus you’ll get all the same side effects that you would get if you deleted the app in the Finder. For example, if I have QNE2TransparentProxyMac installed with its embedded sysex activated, this script will trigger the confirmation UI:

tell application "Finder"
	delete application file "QNE2TransparentProxyMac" of folder "Applications" of disk "Lefty"
end tell

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Are uninstall routines ever run for normal macOS app removal?
 
 
Q