elevating a unix command with do shell script

Hi All

I’m writing an Applescript which retrieves a users home folder from a sever and replaces the current logged in user home folder (this is part of an deployment process that I’m working on).
If i do this interactively in Terminal I would first run the “su admin” command and then run “cp” command. In trying to script this I’ve got this far;


on run
	set this_user to system attribute "USER" as string
	set the_path to POSIX path of "Volumes/UserArchive/" & this_user
	do shell script "su admin; cp -Rp " & the_path & " /Users" user name "admin" password "password" with administrator privileges
end run

When I run this, it seems to get as far as the “su admin” and no further
I’ve searched this excellent site so far but have not an answer, I was hoping someone could shed some light on where I’m going wrong.

Thanks in advance

PS any idea when scriptbuilders will be back online? I’ve been looking for info on adding progress bars

su admin fails, lacking a username/password combo and the do shell script returns an error. Bash never sees anything after the semicolon. You want do shell script “the actual command” with administrator privileges.

Hi Adam

Thanks for taking the time to reply

Yep you’re right, the do shell script returns an error because it’s not running as an elevated process, a standard user does not have sudo rights, which is why i suspect that “cp” is failing even with administrator privileges and whatever combo I’ve tried so far has failed to pass the elevation from “su admin” to the next command.

As I said previously I can do this elevation interactively in Terminal, where I have a problem is achieving the scripted equivalent.

Looks like I’ll have to find anyway round this

Thanks anyway much appreciated