使用AppleScript在Finder中移动文件

4

我只想将一张图片从一个文件夹移动到另一个文件夹,并替换掉已经存在的那张图片:

tell application "Finder"
      copy file "/Users/xx/Documents/img.jpg" to folder "/Users/xx/Documents/State"
   end tell

当我运行它时,我收到一个错误消息,显示:

Finder遇到了一个错误:无法将文件夹[path]设置为文件[path]"."number-10006 from folder [path]

请帮帮我!
3个回答

9

尝试:

tell application "Finder"
    duplicate POSIX file "/Users/xx/Documents/img.jpg" to POSIX file "/Users/xx/Documents/State" with replacing
end tell

或者

tell application "Finder"
    move POSIX file "/Users/xx/Documents/img.jpg" to POSIX file "/Users/xx/Documents/State" with replacing
end tell

3
正如@adayzdone所指出的,此错误出现是因为您使用了未声明的Posix样式路径。
另一种方法是使用冒号分隔的HFS路径,像这样:
move file "Macintosh HD:Users:xx:Documents:img.jpg" ¬
to "Macintosh HD:Users:xx:Documents:State:" with replacing

使用冒号分隔的路径,您需要包含整个路径,包括卷名(我这里假设为Macintosh HD),否则它会抛出错误代码10,006。


1
它帮助了我:

set theSource to POSIX file "/Users/xx/Documents/img.jpg"
set theDest to POSIX file "/Users/xx/Documents/State"

tell application "Finder"
    move theSource to folder theDest with replacing
end tell

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接