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:
Workspace.shared.recycle(…)FileManager().trashItem(…)- 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.