将文件从一个位置复制到另一个位置:访问不允许错误消息

时间:2017-08-17 23:46:51

标签: applescript

我正在制作一个脚本来替换家庭用户库中Containers文件夹中的文件夹。到目前为止,下面的代码工作正常。它没有错。问题是,因为移动文件而不是复制它们,它只能运行一次。但是,如果我尝试将move更改为copy,则会收到以下错误:

无法设置文件路径,替换为«class cfol»的«class ects»((作为字符串的路径)&“Contents:Resources:Folder1”)。不允许访问。

有谁能告诉我为什么会这样,以及如何解决它?

set filepath to (get path to home folder) & "Library:Containers:Folder1" as string
tell application "Finder" to move entire contents of folder ((path to me as string) & "Contents:Resources:Folder1") to filepath with replacing

1 个答案:

答案 0 :(得分:0)

您不能只用move替换copy,因为Finder的AppleScript字典说明了copy 命令的以下内容:

  

复制v :(不可用)将所选项目复制到剪贴板(Finder必须是前端应用程序)

改为使用duplicate 命令

  

重复 v:复制一个或多个对象
  重复说明符:要复制的对象
  [位置说明符]:对象的新位置
  [替换布尔值]:指定是否替换目标中与要复制的项目具有相同名称的项目
  [路由已抑制布尔值]:指定是否自动应用项目(默认为false)。仅在复制到系统文件夹时适用   [完全复制布尔值]:指定是否按原样复制权限/所有权   →说明符:到重复的对象

示例:

set filepath to (get path to home folder) & "Library:Containers:Folder1" as string
tell application "Finder" to duplicate entire contents of folder ((path to me as string) & "Contents:Resources:Folder1") to filepath with replacing