You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AppleScript操作InDesign重链文件报Cannot create the link resource错误求助

问题根源

  • 你当前代码仅提取了拖入文件的文件名,没有获取完整的文件路径,自行拼接的"Macintosh HD" & filename不是合法的完整路径,缺少了文件所在的父目录层级,路径格式本身无效
  • InDesign的relink方法要求传入标准的POSIX路径字符串或者AppleScript文件对象,你拼接的路径不符合格式要求,所以会报URI无效的错误

修复后的代码

on run {input, parameters}
    -- 校验是否有拖入的有效文件
    if (count of input) < 1 then return input
    -- 直接获取拖入文件的完整POSIX路径,不需要手动拼接
    set targetFilePath to POSIX path of (item 1 of input)
    
    tell application "Adobe InDesign 2020"
        activate
        if document 1 exists then
            tell document 1
                -- 先判断目标链接是否存在,避免报错
                if exists link "test1.png" then
                    relink link "test1.png" to targetFilePath
                    update link "test1.png"
                end if
            end tell
        end if
    end tell
    
    return input
end run

关键修改说明

  • 直接从Automator传入的input参数里提取第一个拖入文件的完整POSIX路径,不需要手动拼接磁盘名、文件名,彻底避免路径拼接错误
  • 增加了拖入文件非空校验、目标链接存在校验,避免异常场景报错
  • 移除了不必要的try包裹,后续如果出现其他问题可以直接看到真实报错信息,方便排查
  • 增加了activate命令唤起InDesign到前台,避免后台运行时出现权限拦截问题

内容的提问来源于stack exchange,提问作者user1207524

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.11 16:48:03