How to specify private / var in this code with admin

Hi All,

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?

Thanks

setting to

set TestRM to “private:var:folders”

doesn’t work

(a) Sorted,

figured out that i must specify the hard disk name: set TestRM to “Untitled:private:var:folders”

But still stuck on

(b) How to do it without having to fill in the password prompt

is it something like:

delete (every folder of the folder TestRM) with administrator privileges

Hi,

the Finder cannot modify files with admin or root privileges,
you have to do it with the shell

do shell script "/bin/rm -r /path/to/folder" with administrator privileges

a side note: as you are poking in hidden system folders, I hope you know what you’re doing.

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.