【问题标题】:move a file in finder with applescript使用applescript在finder中移动文件
【发布时间】:2012-12-13 01:01:59
【问题描述】:

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

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

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

Finder 出错:无法将文件夹 [路径] 设置为文件 [路径]"."number -10006 来自文件夹 [路径]

请帮帮我!

【问题讨论】:

    标签: applescript finder


    【解决方案1】:

    试试:

    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
    

    【讨论】:

      【解决方案2】:

      正如@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。

      【讨论】:

        【解决方案3】:

        它帮助了我:

        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
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2012-06-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多