在Mac上调试Applescript以将.docx转换为PDF

时间:2020-07-15 23:27:14

标签: macos pdf applescript file-conversion

我发现提供了一个Applescript,作为对this question的答复,它可以将Word文档(.docx)自动转换为PDF(或也可以批量接受多个文档)。它运行良好,除了会在我无法弄清的最后产生一个错误外,还附加了.pdf扩展名而不删除.docx扩展名,因此文件名为docName.docx.pdf。< / p>

对这些问题的任何帮助将不胜感激。错误的代码和屏幕截图如下。

on run {input, parameters}
    repeat with aFile in input
        tell application "System Events"
            set inputFile to disk item (aFile as text)
            set outputFileName to (((name of inputFile) as text) & ".pdf")
        end tell

        tell application id "com.microsoft.Word"
            activate
            open aFile
            tell active document
                save as it file name outputFileName file format format PDF
                close saving no
            end tell
            set defaultPath to get default file path file path type documents path
        end tell

        tell application "System Events"
            set outputPath to (container of inputFile)
            set outputFile to disk item outputFileName of folder defaultPath
            move outputFile to outputPath
        end tell
    end repeat
    return input
end run

Screenshot of error message

0 个答案:

没有答案