我一直在尝试让系统事件在 AppleScript 中复制文件,但我一直失败:) 我最终总是收到错误“错误“文件无法复制。”编号 -1717”。所以我改变了策略并尝试使用 Finder 来确保我尝试做的事情是正确的。这是有效的代码:
告诉应用程序“系统事件”
set desktopFolder to (path to desktop folder) as string
set fullPath to desktopFolder & "Temp Export From DO"
set theDOEntries to every file of folder "/Users/jkratz/Dropbox/Apps/Day One/Journal.dayone/entries" whose name extension is "doentry"
repeat with DOEntry in theDOEntries
set source to path of DOEntry
log "Source file: " & source
set destination to fullPath as string
log "Destination folder: " & destination
tell application "Finder"
duplicate file source to folder destination with replacing
end tell
end repeat
结束告诉
如果我删除最后一个通知,以便它使用系统事件,我会得到上面提到的相同错误。系统事件标准套件的字典有一个“重复”命令,所以我不确定这里发生了什么。此外,APress 中的“Learning AppleScript,第 3 版”指出:
“系统事件中一个特别烦人的遗漏是它还不能复制文件和文件夹;如果你需要这样做,Finder 是你最好的选择。”
第 3 版是从 2010 年开始的。似乎即使在 Mountain Lion 中这仍然是正确的。谁能证实这一点?1717 错误号将其他任何地方列为处理程序错误,我没有使用处理程序。