Copy A File In AppleScript


I have the code below to set a variable in Applescript for the path to the iTunes Music Folder:

set username to text returned of (display dialog "RingtoneDude" default answer "Enter your path to your iTunes Ringtones folder here. e.g. /Users/David/Music/iTunes/iTunes Music/Ringtones" buttons {"Confirm", "Cancel"} default button 1)

And then I have the code to call the variable username to copy a file

tell application "Finder"
                copy file theCopy to username
            end tell

but the file theCopy which is on the desktop (theCopy is a variable) does not move to the folder.

Please help.

Best Solution

I believe you've misunderstood the copy command. The copy command is used for transferring the contents of one variable into another variable. What you need to use is the duplicate command, which is used for copying files to a specified location. Its syntax is as follows:

duplicate [alias] to [alias]
   [replacing boolean] --If true, replaces files in the destination with the same name

Having said that, your new code, in conjunction with Uriah Carpenter's answer, should look something like this:

set myRingtoneFolder to choose folder with prompt "Select your iTunes Ringtone folder:"
tell application "Finder" to duplicate theCopy to myRingtoneFolder