I would like to understand the recommended App Store–compliant method for uninstalling applications, particularly in cases where certain apps are owned by root rather than the user.
Currently, since root-owned apps cannot be uninstalled, I display the error message: 'App name couldn’t be moved to the Trash because you don’t have permission to access it. please run sudo chown -R $user /application/appname and try again'
I then instruct users to change the ownership of the app and try again, but this approach does not appear to align with App Store policies.
OK.
Lemme start you out with a couple of links:
- On File System Permissions explains the different subsystems that all contribute to file system permissions on macOS.
- BSD Privilege Escalation on macOS describes the various ways to escalate privileges on macOS.
In this case you’re dealing with two types of file system permissions:
- App Sandbox
- BSD
You can get around the first with the coöperation of the user, that is, by having them select the relevant directory in an open or save panel. The issue you’re bumping into in the second.
Consider the permissions on the Applications folder:
% ls -ld /Applications
drwxrwxr-x 89 root admin 2848 Sep 17 14:06 /Applications
To remove application you need to be able to write to this directory. But you can only do that if you’re running as a user in the admin
group. The directory is read-only for standard users.
To get around this you need to escalate privileges. However, the App Review Guidelines specifically proscribe that (clause 2.4.5(v))
I’m only aware of one exception to that rule, namely the NSWorkspace
facility (see BSD Privilege Escalation on macOS for a link to the docs). However, the list of privileged operations it supports doesn’t include deletion.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"