Mac下批量Word转PDF


发布于

|

分类

Pandoc多好用啊~但是Pandoc只支持docx,不支持doc。Win下这样的工具都是收费的,比较坑。于是小伙伴给了一个不完美的AppleScript脚本,通过Mac的「Automatic/自动操作」来运行。

首先找到Automatic,新建一个「工作流程」。最上面搜索「获得指定的访达项目」,拖到右边。然后搜索「运行 Apple Script」,拖到右边,并输入下面一堆咒语:

on run {input, parameters}
	set the_output to {}
	tell application "Microsoft Word"
		repeat with the_file in input
			try
				set pdf_path to my makeNewPath(the_file)
				if not my ifFileExists(pdf_path) then
					open the_file with read only
					set the_doc to the active document
					save as the_doc file format format PDF file name pdf_path
					close the_doc saving no
				end if
			on error error_message number error_number
				close saving no
				log ("ErrorMessage: " & error_message & ", ErrorNumber: " & error_number)
			end try
		end repeat
	end tell
	return the_output
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 if d ends with ".pdf" then
		return d
	else
		return d & ".pdf"
	end if
end makeNewPath

on ifFileExists(f)
	tell application "System Events"
		if exists file f then
			return true
		else
			return false
		end if
	end tell
end ifFileExists

先点击🔨,看看有没有错误。然后将所需要的doc文件拖到「获得指定的访达项目」里面,最后点击最右上角的「▶️运行」。

你会看到一个Word窗口开了又关,开了又关……就转换好了。


之所以说「不完美」是因为,如果文档比较乱,有宏啊啥的,脚本会卡住,需要手动点击「不启用宏」。如果Word打不开,会报错,这时候也需要手动点击两个「确定」。反正只是省去了人工一个一个转换的麻烦,人还是要盯着看的。

而且速度巨慢。

凑合用吧,总比没有强。


评论

  1. cwwwz 的头像
    cwwwz

    请问您一下,就是我试了下,他只能打开word,但是也没有转换pdf,word也打开着不会自动关闭,请问这是什么问题呀?

  2. cwwwz 的头像
    cwwwz

    我想请问一下为什么我允许这个操作,只是所有word打开了,并没有转换成pdf?好奇怪

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注