AppleScript to copy a folder

I’m having a weird problem getting applescript to copy a folder to a user’s Home directory. The home folder is network based but I’m having the problem locally as well. It works fine in the user that I’m scripting in but when I log in as a fresh user and run it I get the error.

‘Can’t set “Macintosh HD:private:var:automount:Network:Servers:serverpath:userhome:Library:” to <> “Preferences” of application “Finder”.’

This is the script.

tell application “Finder”
set userHome to home
set thePath to ((userHome as string) & “Library:”)
duplicate folder “Preferences” to thePath with replacing
display dialog “Preferences Copied.”
end tell

The Preferences folder I’ve placed in the Package contents but I’ve tried it with it sitting in a folder. I’ve also tried setting permissions differently on the Prefs folder but that doesn’t seem to matter. What’s even stranger is after making a couple changes to the file and resaving (logged in as the new user) it eventually works. Any ideas would be GREATLY appreciated.

Thanks,
Joe

I figured out the problem but I’m still stuck. I’m trying to copy a folder that I’ve put in the package Contents of the file. How would I do that? What would the proper path be? Thanks.

Does this work? It might need to be tweaked based on the hierarchy of the package.

set me_ to path to me as text
set myPrefs to (me_ & "Contents:Preferences:")

tell application "Finder"
	set userHome to home as text
	set thePath to (userHome & "Library:")
	try
		duplicate folder myPrefs to thePath with replacing
		display dialog "Preferences Copied."
	on error e
		display dialog e buttons {"OK"} default button 1 with icon 0
	end try
end tell

– Rob

Thanks a million for the help. Unfortunately that didn’t work for some reason. I tried just copying it to the desktop and that didn’t work either.

The “path to me” command will work only when the script is saved as an application. Did you save it as an app and then launch the app?

– Rob

Ok, I believe this is a network home issue. It works fine when logged in as a local user. I think it’s choking on the long network path. Somehow the path isn’t correct.

The path that applescript pulls is:
“Macintosh HD:private:var:automount:Network:Servers:bcm:Volumes:areas:IT:TS:test:Library:”

I think the real path is that minus the “Macintosh HD:” or:
“private:var:automount:Network:Servers:bcm:Volumes:areas:IT:TS:test:Library:”

Is there a way I can tell it to chop of the “Macintosh HD:”?

Thanks for your help, I appreciate it.

removing the “Macintosh HD:” didn’t work either.

Man I’m so confused. It WILL copy a folder from the desktop to a network home but it won’t copy it from the file contents unless I’m in as a local user.

Ha, it works if I move the app to the shared folder. Thanks for your help.