Applescript: Admin Privileges

It's my understanding that you can only use "with administrator privileges" for a shell script.


In my AppleScript, I have several statements as follows:

duplicate POSIX file "/path/to/file" to POSIX file "/path/to/file" with replacing

The new location of these files requires an administrator username and password to modify it. The script runs without error and works exactly as I intended, except that Finder asks the user to enter their password for every single file that's moved. Is there any way I can just have them enter the password once to grant permission to move all the files?

 MacBook Pro with Retina display-OTHER, OS X Mavericks (10.9.5), 15 in, Late 2013, 256GB, 8GB RAM

Posted on Nov 30, 2014 10:29 AM

Reply
20 replies

Nov 30, 2014 11:47 AM in response to stevejobsfan0123

Ah, ok, try changing the permissions of the script file so that it is owned by root, and/or place the script down in the system area (say /Library/Scripts) so that it will run with raised permissions.


Restarting the Finder as root is ridiculous overkill, and will open your device to heaven-knows how many security problems. I wish people wouldn't give advice like that. It sounds cool and techy, yes, but it's like trying to swat a fly with a baseball bat, and likely to produce the same Adam Sandler movie type results.

Dec 1, 2014 1:09 PM in response to Niel

OK... almost there. That part of the code works flawlessly now. The very last step of the code involves finding and removing a file. I have:

set toRemove to do shell script "sudo find /path/to/folder -name nameofthefile"

do shell script "sudo rm" + toRemove + ""


toRemove correctly stores the POSIX file path. However, once it gets to the "sudo rm" line, it gets an error. I assume it is some sort of type-conversion error?

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript: Admin Privileges

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.