Macos 在Applescript中移动文件时,出现错误:";Finder出现错误:处理程序可以’;t处理此类对象。”;

Macos 在Applescript中移动文件时,出现错误:";Finder出现错误:处理程序可以’;t处理此类对象。”;,macos,error-handling,applescript,file-moving,Macos,Error Handling,Applescript,File Moving,我尝试使用Applescript移动文件,每次运行应用程序时都会出错。在应用程序的内容中,我有我想要移动的文件(因此,如果我分发应用程序,用户不必单独下载文件)。这也是我使用((主文件夹的路径为文本)并将特定文件路径添加到该路径之后的原因。以下是我的代码: set source to ((path to home folder as text) & "/Contents/Resources/finder.jpg") set source2 to ((path to home folder

我尝试使用Applescript移动文件,每次运行应用程序时都会出错。在应用程序的内容中,我有我想要移动的文件(因此,如果我分发应用程序,用户不必单独下载文件)。这也是我使用
((主文件夹的路径为文本)
并将特定文件路径添加到该路径之后的原因。以下是我的代码:

set source to ((path to home folder as text) & "/Contents/Resources/finder.jpg")
set source2 to ((path to home folder as text) & "/Contents/Resources/finder@2x.jpg")

set destination to alias "Macintosh HD:System:Library:CoreServices:Dock.app:Contents:Resources:"

tell application "Finder"
    move source to destination with replacing
    move source2 to destination with replacing
end tell

p、 我检查了这里几乎所有相关的问题/答案,没有一个有用。

一个简单的
显示对话框源代码将引导您找到解决方案:

  • path to home folder
    别名返回到您的home文件夹(Macintosh HD:Users:your name:)。我想您想要的是
    path to me
    指向您的应用程序
  • analias as text
    使用作为分隔符返回路径字符串,并附加使用/分隔路径组件的部分
  • analias as text
    返回路径字符串,对于目录,该字符串以结尾:
  • 小结:试试看

    set source to ((path to me as text) & "Contents:Resources:finder.jpg")
    
    更新: 您不能使用
    别名…
    ,更好的用法是
    …因为别名
    ,我认为,
    复制
    在这里可能更好

    set source to ((path to me as text) & "Contents:Resources:finder.jpg") as alias
    set source2 to ((path to me as text) & "Contents:Resources:finder@2x.jpg") as alias
    
    set destination to "Macintosh HD:System:Library:CoreServices:Dock.app:Contents:Resources:" as alias
    
    tell application "Finder"
        duplicate source to destination with replacing
        duplicate source2 to destination with replacing
    end tell
    

    享受吧,Michael/Hamburg,这很有帮助,但我仍然得到了一个错误:“Finder出现了一个错误:处理程序无法处理这个类的对象。”此错误突出显示了使用替换将源移动到目标的
    ,这导致我认为我的移动方法有问题。我相信您需要在
    源前面添加
    文件
    很好!你也可以将所有路径定义为别名。我更新了我的答案!现在它告诉我
    文件Macintosh HD:Users:[我的用户名]:Desktop:App.App:Contents:Resources:finder.jpg未找到。
    使用SKcript编辑器打开捆绑包滑块,查看文件是否在那里。如果没有,请将其拖到该位置。