使用applescript在finder中移动文件

时间:2012-12-27 16:43:04

标签: applescript finder

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

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

当我运行它时,我收到一条错误消息

  

Finder收到错误:无法将文件夹[path]设置为文件[path]“。”编号   文件夹[路径]

中的-10006

请帮助我!

2 个答案:

答案 0 :(得分:6)

尝试:

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

答案 1 :(得分: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。