thanks to people of this forum who helped me make this script
tell application "Finder" to set disks_ to name of disks whose startup is false
set chosen_ to choose from list disks_ with prompt "Choose a volume to copy to."
if chosen_ is false then return -- user canceled, quit script�
set originalFile to "Macintosh HD:Users:Shared:01.pdf"
display dialog "What should the new file be called?" default answer "New_Name"
set Newname to the text returned of result & ".pdf"
do shell script "ditto " & quoted form of (POSIX path of originalFile) & "� " & (POSIX path of chosen_) & "/" & Newname
works very well for me.
Now the issue !!!
These scripts are going to run many times by different users to copy files from one location to other external drive.
if the user type “New_Name.pdf” two times by mistake than the script replace the first pdf with the second pdf.
its not good for me.
it would great if the script check for existing file name in the selected drive and prompt with new dialog box telling user that the file already exist please select another name.
hope you guys got me if not please let me know because my last post on this topic was lost, parhaps i have not explained my issue well.
thanks
Does this work? (Incidentally, you should use the quoted form of the POSIX path since the user may put a space in the new name and that would cause problems.)
tell application "Finder" to set disks_ to name of disks whose startup is false
set chosen_ to choose from list disks_ with prompt "Choose a volume to copy to."
if chosen_ is false then return -- user canceled, quit script??
set originalFile to "Macintosh HD:Users:Shared:01.pdf"
set Newname to "New_Name"
set the_error to ""
repeat
if the_error is not "" then set the_error to the_error & return & return
set Newname to text returned of (display dialog the_error & "What should the new file be called?" default answer Newname)
try
get (chosen_ & ":" & Newname & ".pdf") as alias
set the_error to "" & Newname & " already exists. Please try again."
on error
exit repeat
end try
end repeat
do shell script "ditto " & quoted form of (POSIX path of originalFile) & "? " & (quoted form of (POSIX path of chosen_) & "/" & Newname & ".pdf")
thanks john8 for response.
i have been playing around your script from yesterday when you send me the script.
here is the problem
when i run the script as you have sent me it gives me the error “file not found”
but if change the script from this
do shell script "ditto " & quoted form of (POSIX path of originalFile) & " " & (quoted form of (POSIX path of chosen_) & "/" & Newname & ".pdf")
to
do shell script "ditto " & quoted form of (POSIX path of originalFile) & " " & quoted form of (POSIX path of chosen_) & "/" & Newname & ".pdf"
it sees the file and copy the file as typed in New_Name dialog box. But the second part doesn’t .
if the file exist it just stop the script without doing any thing
please give me some suggestion
thanks
I was wrong in my last reply
those brackets are not the problem but there is something which i could not figure out to make john8’s script work.
when i run john8’s script it copy the file but if the same name file exist on the selected drive then it just replace it without any warning.
Please help me solve this mystry.
thanks
thanks john8 for giving me startup.