applescript - 使用 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)
解决方案
我设法使用以下脚本将 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
)。
推荐阅读
- java - 如何在 Java 中执行 Scala 的 Seq++ 操作数
- ios - Alamofire objectmapper 的 Xcode 10 更新问题
- javascript - 如何在以下代码中添加 Get 或 POST 请求
- go - 参考内部结构
- image - 张量流中的分层图像分类
- python - powershell stderr 重定向每隔几个字符就换行
- rust - 无法在“FnMut”闭包中移出捕获的变量
- arrays - 如何在 C++ 中创建一个添加多个数组的函数
- php - 如何在控制器功能中使用表单输入来输入验证码以保护 CodeIgniter 中的表单提交(不是验证而是验证)
- java - 使用 Streams 的 JsonArray 循环