MacOS Automator + Applescript 用于将 docx 导出为 pdf 的解决方案

Bas*_*e_v 5 macos applescript ms-word automator word-2016

在阅读了很多关于此的不同主题并尝试了一堆脚本后,我挠头,但似乎都没有工作。

我想使用 Automator 自动将 Word 2016 的精选 docx 文件转换为 pdf。


使用了以下 Automator 服务:

在此处输入图片说明


使用了以下脚本:

on run {input, parameters}
    tell application id "com.microsoft.Word"
        activate
        open input
        set doc to name of active window
        set theOutputPath to (input & ".pdf")
        save as active document file name theOutputPath file format format PDF
    end tell
end run
Run Code Online (Sandbox Code Playgroud)


这会导致错误:Microsoft Word 出现错误:活动文档不理解“另存为”消息。

vad*_*ian 7

主要问题是这input是一个列表。您必须使用重复循环来分别处理每个文件

我在转换后添加了一行来关闭当前文档

on run {input, parameters}
    tell application id "com.microsoft.Word"
        activate
        repeat with aFile in input
            open aFile
            set theOutputPath to ((aFile as text) & ".pdf")
            tell active document
                save as it file name theOutputPath file format format PDF
                close saving no
            end tell
        end repeat
    end tell
end run
Run Code Online (Sandbox Code Playgroud)