使用Applescript将图像文件夹复制到另一个文件夹时遇到问题

时间:2020-02-04 21:51:39

标签: applescript repeat

我收到一个关于无法将别名...变成整数的错误?不确定...

我正在尝试使此片段包含几个文件夹(每个文件夹中都有一堆图像)并将其内容复制到存档驱动器。

on open droppedItems

    set user to do shell script "whoami"
    set archivePath to "/Users/" & user & "/Desktop/Archive' 'Drive"

    #tell application "Finder" to set jobName to name of item droppedItems
    #I need to figure this out as it's not working the way I originally had it

    tell application "Finder"
        do shell script "mkdir -p " & archivePath & "/" & jobName & "RAW' 'FILES"
        set localDestination to archivePath & "/" & jobName & "RAW' 'FILES"
        do shell script "open " & localDestination
        activate
        set position of window 1 to {1000, 0}
    end tell

    **#this is where I'm having issues (obviously)**
    repeat with i from 1 to count of droppedItems
        set currentItem to item i of droppedItems
        #display dialog (currentItem)
        duplicate currentItem to localDestination #I've tried a few different things here...
    end repeat
end open

1 个答案:

答案 0 :(得分:1)

代码中有很多问题。

最重要的是

  1. droppedItems是项目的列表。要获得名称,您必须使用一项。
  2. Finder仅接受HFS路径(以冒号分隔),您甚至试图将文件复制为文字字符串。使用HFS路径,您无需转义空格字符。在do shell script行中,路径以quoted form of进行转义。
  3. duplicate命令属于Finder。它必须包装在tell application "Finder"块中。

“查找器”窗口不相关。您可以在没有打开窗口的情况下复制项目。但是我添加了一行来打开文件夹。而且您也不需要重复循环。

on open droppedItems

    set archivePath to (path to desktop as text) & "Archive Drive"
    tell application "Finder" to set jobName to name of first item of droppedItems
    set localDestination to archivePath & ":" & jobName & "RAW FILES"
    do shell script "mkdir -p " & quoted form of POSIX path of localDestination
    tell application "Finder"
        duplicate droppedItems to folder localDestination
        open folder localDestination
    end tell

end open

如果您只想复制文件夹的内容,则确实需要重复循环

on open droppedItems

    set archivePath to (path to desktop as text) & "Archive Drive"
    tell application "Finder" to set jobName to name of first item of droppedItems
    set localDestination to archivePath & ":" & jobName & "RAW FILES"
    do shell script "mkdir -p " & quoted form of POSIX path of localDestination
    tell application "Finder"
        repeat with anItem in droppedItems
            if class of anItem is folder then
                duplicate every item of anItem to folder localDestination
            else
                duplicate anItem to folder localDestination
            end if
        end repeat
        open folder localDestination
    end tell

end open
相关问题