Duplicate files won't work

Sorry for the litany of posts lately, but I’m getting frustrated. Following is a part of a long XCode Script:

tell application "Finder"
	set d to ":"
	set newName to "TempUser"
	set userName to last word of (path to current user folder as text)
	set startDisk to name of startup disk
	set userHome to home as text
	set destinFolder to "Macintosh HD:Users:Shared:"
	
	with timeout of 5000 seconds
		try
			duplicate userHome to destinFolder
			tell me to log "copying " & userHome & "to " & destinFolder
			duplicate userHome to destinFolder
		on error
			tell me to log "Finder action failed - trying shell"
			set x to destinFolder & userName
			try
				tell me to log "Erasing Finder folder"
				do shell script "sudo rm -r " & x password pass with administrator privileges
			end try
			tell me to log "Doing shell script copy"
			do shell script "sudo cp -Rp ~ /Users/Shared" password pass with administrator privileges
		end try
		tell me to log "userHome duplicated"
	end timeout
end tell

I would love for this to take place in either the Finder or the Terminal, but I’ve had problems with both - as such - I have the try command.
When I manually copy the Users home folder to the Shared folder, there are no problems. Every time I try to use my script - which is ostensibly doing the same thing - I get the error that the folder already exists in that location. For the record - the variable “pass” is defined earlier in the script - so this is not the issue. Frequently, the shell script gives me a man page type error. What am I doing wrong? Is there a way to copy a folder outside of using duplicate? Have I put bad parameters in the shell command? I’ve even tried adding “with replacing” to the Finder script, but to no avail. I either get a privilege error, a “This file does not exist” error, or something similar. Before I beat myself to death with my 20’’ iMac, can someone offer assistance?

-B

Hi shriere,

i tried this:

with timeout of 3000 seconds
	tell application "Finder"
		set dup to "Music"
		set shr to folder "Shared" of (path to users folder)
		try
			set name of folder dup of shr to "Music_bak"
		end try
		duplicate (path to music folder) to shr
		try
			delete folder "Music_bak" of shr
		end try
	end tell
end timeout

If there is already a ‘Music’ folder it renames it, then duplicates the original and trashes the renamed backup afterwards. Seems to work here without problems (I didn’t try to duplicate my whole users folder since it’s to large.)
If you don’t want this backup thing you of course can also delete it as first step and omit the set name line.

Hope that helps …

D.