问题
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.
回答1:
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
回答2:
I would suggest you use choose folder which returns an alias
.
To make some text into an alias object use set myAliasPath to myTextPath as alias
.
For more detailed information see Aliases and Files in the AppleScript documentation.
来源:https://stackoverflow.com/questions/5134568/copy-a-file-in-applescript