macos - 在Applescript中移动文件,出现错误: “Finder got an error: Handler can’ t handle objects of this class.”

标签 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

ps我几乎检查了这里的每个相关问题/答案,但都无济于事。

最佳答案

一个简单的display dialog source将带您找到解决方案:

  • path to home folder别名返回到您的 HOME 文件夹(Macintosh HD:用户:您的名称:)。我认为您想使用path to me代替它指向您的应用程序。
  • analias as text返回使用:作为分隔符的路径字符串,并附加使用/分隔路径组件
  • 的部分
  • analias as text返回以结尾的路径字符串:对于目录
  • ,为

    摘要:尝试
    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
    

    享受,迈克尔/汉堡

    关于macos - 在Applescript中移动文件,出现错误: “Finder got an error: Handler can’ t handle objects of this class.”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29090072/

    相关文章:

    shell - sqlite3 的转义引号

    macos - Mac 应用程序如何确定启动它的方法?

    objective-c - WebKit 框架中的shouldStartLoadWithRequest 等效项?

    python - IndexError : list index out of range - throwing error in Python?

    java - 用于运行 .jar 的 Shell 脚本可以从终端运行,但不能从 AppleScript 运行

    dictionary - 如何使用 AppleScript 在 Mac OS X 词典中查找单词?

    objective-c - 从 Today 扩展应用程序发送系统事件

    macos - 在没有 Mac 开发者程序的情况下签署 Mac 应用程序

    C++ std::list 作为静态成员变量——并发问题?

    android - Android RxJava和Realm-RxJava错误处理是否可以捕获Realm发生的错误?