在Applescript中移动文件时出现错误:" Finder收到错误:处理程序无法处理此类对象。"

时间:2015-03-17 01:57:01

标签: macos error-handling applescript file-moving

我正在尝试使用Applescript移动文件,每次运行应用程序时都会出错。在应用程序的内容中,我有我想要移动的文件(因此,如果我分发应用程序,用户将不必单独下载文件)。这也是我使用((path to home folder as text)并添加特定文件路径的原因。这是我的代码:

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.S。我在这里检查了几乎所有相关的问题/答案,没有人帮忙。

1 个答案:

答案 0 :(得分:0)

一个简单的display dialog source会引导您找到解决方案:

  1. path to home folder会将别名返回到 HOME 文件夹(Macintosh HD:用户:您的名字:)。我认为您想要path to me而不是指向您的应用。
  2. analias as text使用作为分隔符返回路径字符串,并附加使用 / 分隔路径组件的部分
  3. analias as text返回以结尾的路径字符串:以防目录
  4. 摘要:尝试

    set source to ((path to me as text) & "Contents:Resources:finder.jpg")
    

    <强>更新 你不能使用alias ...,更好的使用是... as alias,我想,也许duplicate在这里更好......

    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
    

    享受,迈克尔/汉堡