mac如何利用 applescript 批量将word转换成pdf

该脚本使用AppleScript打开文件选择对话框,让用户选择多个Word文档,然后将这些文档转换为PDF格式。它通过MicrosoftWord应用程序进行转换,并处理可能出现的访问权限问题。

没有更多的废话,直接上代码,代码的注释应该很清楚了。

property word_docs : {"org.openxmlformats.wordprocessingml.document", "com.microsoft.word.doc"}
property default_path : (path to desktop) as alias
property Delim : {".docx", ".doc"}
property PDF : ".pdf"

set outPDF to {}

-- 打开文件选择对话框,只允许选择Word文档,并将所选文件存储在变量 selected_files 中
set selected_files to (choose file of type word_docs default location default_path with multiple selections allowed without invisibles and showing package contents)

-- 将Word文档的扩展名替换为PDF,并将PDF文件路径添加到 outPDF 列表中
set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, Delim}
repeat with afile in selected_files
    copy item 1 of text items of (afile as text) & PDF to the end of outPDF
end repeat
set AppleScript's text item delimiters to TID

-- 使用Microsoft Word应用程序对象
tell application id "com.microsoft.Word"
    -- 将Microsoft Word窗口设置为活动窗口
    activate
    -- 循环遍历所选的Word文档
    repeat with i from 1 to count of s
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值