首页 > 解决方案 > 使用 Applescript 将页面导出到 Microsoft Word 失败

问题描述

我目前正在尝试使用简单的 applescript 脚本将 iWork .pages 文件导出到 Microsoft Word .docx 文件。

on run {path, fileName}

tell application "Pages"
set theDoc to open (path & "/" & fileName)

set theDocName to name of theDoc
export theDoc as Microsoft Word to file ((path & "/" & theDocName & ".docx") as text)

close theDoc

end tell
end run

我希望将文档导出为 Microsoft Word 文档,但是我收到以下错误:

Pages got an error: The document “1” could not be exported as “/Users/joshgrimmett/Desktop/pages2docs/in/1”. (6)

标签: applescriptiworkapplescript-numbers

解决方案


我设法使用以下脚本将 Pages 文档导出到 Word:

on run(_dirname, _filename)
    tell application "Pages"
        set theDoc to open (_dirname & _filename)
        set theDocName to name of theDoc
        set dst to (_dirname & theDocName & ".docx")
        export theDoc to POSIX file dst as Microsoft Word
        close theDoc
    end tell
end run

/Users/joshgrimmett/Desktop/pages2docs/in/使用例如和foo.pages(或任何其他 Pages-support 扩展)作为参数调用脚本。我认为问题在于使用path(它是 AS 中的保留关键字)作为变量,而不是指定目标类(因为我们使用的是 POSIX 路径而不是别名,所以它是POSIX file)。


推荐阅读