Applescript with additional administrator rights
I need to run a script as part of the first phase of an application to remove some deprecated components from the previous version. Usually these components are installed in $ HOME / Library or / Library, and the script can just move them to the trash.
The problem is that in the case where the user is not an administrator and the components are in the global / library, the script must authenticate as an administrator, otherwise it will fail. My current script is using AppleScript, but to my surprise, I cannot find a way to become an admin user in the middle of the script.
There's a `do shell script 'foo' with an admin privilege command, but it's always authenticated, and it's easier to express the steps I want in AppleScript than a shell, although it's not impossible.
At the moment I am running into trying to move files in AppleScript, catching the fail of the move, and then using shell-script authentication to move files using "mv". It seems very cumbersome, so what can I do to make things tidy?
source to share