I have a chunk of applescript that i am trying to get to run:
set TestRM to (path to home folder as text) & "Library:Application Support:Handbrake:"
tell application "Finder"
delete (every folder of the folder TestRM)
end tell
I am making a script that needs to access private/var/folders (when unhidden). Can someone advise
(a) How i would provide the variable (TestRM)
(b) How i would get it to do it with Administrator Privileges?
Like stefan said, you have to know what you’re doing however if it’s for own use and don’t want to type in each time your password you can do this (the recommended way):
do shell script "command" password "<password>" with administrator privileges
You can do this sudo as well. You can pipe the password to stdin of sudo command. This way you automatically fill in the password for sudo and don’t need to do it by hand.
NOTE! Apple tells clearly not to use sudo in a do shell script but you should use the “with administrator privileges” property of the command instead. Still this is a way for shell scripting so I still want to share this.
do shell script "echo '<password>' | sudo -S <command>"
This approach requires that the current user is in the sudoer file listed.