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

问题描述 投票:0回答:1

我收到有关无法将别名...设为整数的错误?不确定...

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

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
applescript repeat
1个回答
0
投票

代码中有很多问题。

最重要的是

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

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
© www.soinside.com 2019 - 2024. All rights reserved.