Copy A File In AppleScript

浪尽此生 提交于 2019-12-24 08:23:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!