使用AppleScript复制多个文件

使用AppleScript复制多个文件,applescript,Applescript,我必须使用AppleScript复制多个文件。这个脚本应该做的是,首先,让用户选择包含必须复制的文件的文件夹。其次,显示用户选择的文件夹中的所有文件的列表。在此步骤中,用户可以选择多个文件。最后一步是复制文件。下面是我使用的脚本: --Get the folder set theFolder to (choose folder with prompt "Select the folder that contains the files to copy. In the next step you'

我必须使用AppleScript复制多个文件。这个脚本应该做的是,首先,让用户选择包含必须复制的文件的文件夹。其次,显示用户选择的文件夹中的所有文件的列表。在此步骤中,用户可以选择多个文件。最后一步是复制文件。下面是我使用的脚本:

--Get the folder
set theFolder to (choose folder with prompt "Select the folder that contains the files to copy. In the next step you'll be able to select the files to copy.") as text

--Get the path to de destination folder of the files
set destination_folder to (path to home folder) as text

--Generate the list of files inside theFolder
tell application "Finder"
    set theItems to items of folder theFolder
    set theNames to {}
    repeat with anItem in theItems
        set end of theNames to name of anItem
    end repeat
end tell

-Let user select the files of the list
choose from list theNames with prompt "Select the files" OK button name "OK" cancel button name "Cancel" with multiple selections allowed

tell result
    if it is false then error number -128 -- cancel
    set theChoices to it
end tell

if (count of theChoices) is greater than or equal to 1 then
repeat with aChoice in theChoices
    set thisItem to theFolder & aChoice
    -- do something with thisItem
    duplicate thisItem to destination_folder
end repeat
end if
问题是,当srcipt必须运行“将此项复制到目标文件夹”行时,它会崩溃。以下是我尝试运行时生成AppleScript编辑器的oputput:

tell application "AppleScript Editor"
    choose from list {"Obres.xlsx", "Programa_sardanes", "Sardanes.xlsx"} with prompt "Escull els arxius o l'arxiu que vols afegir" OK button name "Acceptar" cancel button name "Cancelar" with    multiple selections allowed
    --> {"Sardanes.xlsx"}
-- 'core'\'clon'{ 'insh':'utxt'("Macintosh HD:Users:Joan:"), '----':'utxt'("Macintosh HD:Users:Joan:MEGA:Sardanes.xlsx"), &'subj':null(), &'csig':65536 }
    --> error number -1700 from "Macintosh HD:Users:Joan:MEGA:Sardanes.xlsx" to reference
Result:
error "Can't generate \"Macintosh HD:Users:Joan:MEGA:Sardanes.xlsx\" on the type reference." number -1700 from "Macintosh HD:Users:Joan:MEGA:Sardanes.xlsx" to reference

我已经尝试了几个小时来解决这个问题,但我不知道脚本上的错误在哪里。我希望有人能帮助我。如果有人知道一个更简单的方法,这也会很有帮助。谢谢大家!

我对你的脚本做了一些小改动,现在应该可以了

基本上,你少了几份。“duplicate”命令是“Finder”的一个功能,因此我在复制部分添加了一个“Tell application”Finder“”。您还将文件和文件夹的路径存储为文本,我将它们修改为“别名”

on run
--Get the folder
set theFolder to (choose folder with prompt "Select the folder that contains the files to copy. In the next step you'll be able to select the files to copy.") as text

--Get the path to de destination folder of the files
set destination_folder to (path to home folder)

--Generate the list of files inside theFolder
tell application "Finder"
    set theItems to items of folder theFolder
    set theNames to {}
    repeat with anItem in theItems
        set end of theNames to name of anItem
    end repeat
end tell

--Let user select the files of the list
choose from list theNames with prompt "Select the files" OK button name "OK" cancel button name "Cancel" with multiple selections allowed

tell result
    if it is false then error number -128 -- cancel
    set theChoices to it
end tell

if (count of theChoices) is greater than or equal to 1 then
    repeat with aChoice in theChoices
        set thisItem to (theFolder & aChoice) as alias
        -- do something with thisItem
        tell application "Finder" to duplicate thisItem to destination_folder
    end repeat
end if
end run