copy files

I simply want to copy files from hard drive to external hard drive
here is the script I am using

 set originalFile to alias "Macintosh HD:Users:pao62c01.xls" 
 set originalFile to POSIX path of originalFile 
 set dests to "/Volumes/SPEC" 
 do shell script "ditto " & quoted form of originalFile & space & quoted form of dests 
 

here the destination volume is selected as “SPEC”
But I want user to select the volume.
I mean when script runs a dialog box appears and prompt user to select the drive.

thanks

Does this work?

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:pao62c01.xls"
tell application "Finder" to duplicate alias originalFile to alias (chosen_ & ":" as text)

– Rob

thanks rob
thats good
but you know my first script was written to work from simple finder.
your script works great but in my case the user who is going to use this script has just access to simple finder. that is why somebody suggest me to use shell sript something like this

do shell script "ditto " & quoted form of originalFile & space & quoted form of dests  
 

this works great with simple finder.
the only problem with my first is that it doesn’t prompt to select the drive.

Please give some suggestions

Not sure what the limitations of the simple finder are but you probably could use the first part of rob’s script then use the shell script once the volumes are identified and copy it that way

the attached script could use some error handling and other bits to isolate only the writable volumes and to exclude the Startup volume

set disks_ to do shell script “cd //volumes ;ls -1” as list
set olddelimiter to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to (return)
set disks_ to the text items of disks_
set AppleScript’s text item delimiters to olddelimiter
display dialog thevolumes
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:jbradfield:Desktop:mss001.tif”

set Newname to “New_name”

do shell script "mv " & (POSIX path of originalFile) & " " & (POSIX path of chosen_) –tell application “Finder” to duplicate alias originalFile to alias (chosen_ & “:” as text)

this script was automatically tagged for
color coded syntax by Script to Markup Code
written by Jonathan Nathan

thanks
joe

that work for me

forgive stupidity, but why use posix path?

not sure that that is stupid cause i’m not sure why

but whenever i do a shell script i always use the posix form

i Guess it helps to resolve spaces and : vs / issues when parsing a path to use in a shell script

unless someone else can answer it better that is all i’ve got

The ‘traditional’ Mac OS uses colon-delimited pathnames with the disk name as the root.
For example:

Macintosh HD:Users:username:documents:file.txt

All AppleScript’s file-based objects (file, alias, folder, etc.) will return these types of paths.

Unix apps, on the other hand, (including all shell utilities) use Unix-style pathnames that are slash-delimited. Additionally, unix paths can be absolute (they start with a /), relative to the current working directory (starts with a file or directory name), or relative to the user’s home directory (starts with the ~ symbol). For example, the above file in unix style might be:

/Users/username/documents/file.txt

Or, even:

~/documents/file.txt

The AppleScript command ‘posix path’ converts a Mac OS-style (colon-delimited) path into a Unix style path. The posix path is then suitable for including in a shell command.

A unix shell would choke on the command:

cat Macintosh HD:Users:username:documents:file.txt

but has no problem with:

cat ~/documents/file.txt

Additionally, just to be safe, if you’re including posix paths in shell commands, you should add the ‘quoted form of’ command to properly quote the path name, just in case it has spaces or other characters that might confuse a shell.

In short:

set aFile to file “Macintosh HD:Users:username:documents:file.txt”
→ file “Macintosh HD:Users:username:documents:file.txt”
posix path of aFile
→ ~/documents/file.txt
quoted form of posix path of a file
→ ‘~/documents/file.txt’

(note the quotes around the ‘quoted form’ example, which would be required if the path contained a space)