【笔记】MacOS批量将Word文件转换成PDF文件

前言

MacOS利用自动操作批量将Word文件转换成PDF文件

编写脚本

  • 打开自动操作.app->选择文稿类型为工作流程->选取

  • 拖拽一个获得指定访达项目模块

  • 拖拽一个运行AppleScript模块

  • 填写代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
on run {input, parameters}
set theOutput to {}
tell application "Microsoft Word"
repeat with thefile in input
open thefile
set pdfPath to my makeNewPath(thefile)
set theActiveDoc to the active document
save as theActiveDoc file format format PDF file name pdfPath
close theActiveDoc saving no
end repeat
end tell
return theOutput
end run

on makeNewPath(f)
set d to f as string
if d ends with ".docx" then
return (text 1 thru -5 of d) & "pdf"
else if d ends with ".doc" then
return (text 1 thru -4 of d) & "pdf"
else
return d & ".pdf"
end if
end makeNewPath

启动脚本

  • 添加需要转换的文件,启动脚本,得到转换后的文件

执行脚本期间,可能出现申请权限的弹窗,此时直接给予权限既可

踩坑

  • 可能出现申请权限的弹窗

解决问题

  • 此时直接赋予权限即可

踩坑

  • 首次执行脚本报错:“Microsoft Word”遇到一个错误:“missing value”不理解“save as”信息。

解决问题

  • 再次执行脚本即可

完成

参考文献

知乎——我是龙律师