I’m sort of a newbie, coming to applescript from xml and a bit of UNIX and java.
How does one go about copying one file to another in applescript? I want to copy file_a to file_b so that the contents of file_a overwrite what’s in file_b. And I need to do it in applescript (that’s how my boss asked me to do it).
Any suggestions? Tips? I’ll send you a bucket of good karma and a shiny penny…
Best,
Laurel Maury
Model: OS 10.4.6
AppleScript: 1.10.6
Browser: Safari 417.9.3
Operating System: Mac OS X (10.4)
I am not sure about this, because if I understand it correctly the filename of file_a is not the same as file_b ?
If the name of the file is the same, you can use a script like this:
tell application “Finder”
set file_a to “here the path of file_a” as alias
set Folder_file_b to “here the path of the folder of file_b” as alias
duplicate file_a to Folder_file_b with replacing
end tell
since you are from Unix, you might find something like this more comfortable:
set file_a to "~/Desktop/atestfile.txt"
set file_b to "~/Desktop/btestfile.txt"
try
do shell script "/bin/cat " & file_a & " > " & file_b
display dialog "Your file has been overwritten."
on error
display dialog file_a & " does not exist!"
end try