AppleScript - 调用 Pages 将文件导出为 docx

在这里插入图片描述


macOS 使用交流 QQ 群:658095824,V : ez-code


python 无法直接操作 doc,只能操作 docx;
win2com 可以将 doc 转化为 docx,可惜无法在 linux/macOS 下安装 win32com;

使用 Pages 打开 doc,可以导出到 docx;
然而手动导出注定是繁琐的,这时想到可以使用 AppleScript 来操作 Pages


代码实现

如下代码实现了将 pages 文件导出为 docx

tell application "Pages"
	set thisDoc to open "/Users/user/Desktop/奥运会.pages" 
	export thisDoc to POSIX file "/Users/user/Desktop/a.docx" as Microsoft Word
	delay 2
	close thisDoc
end tell

关于 POSIX-style

很多用户出现各种问题,是因为 file path 前面没有添加 POSIX;
/Users/user/Desktop/a.docx 是一个 POSIX 风格路径;

Some scriptable apps are designed to work with POSIX-style paths, rather than AppleScript alias and file objects. Like a file object, a POSIX file object is not dynamic and can also refer to an item that doesn’t exist yet.

A POSIX file object is displayed as a slash-delimited path preceded by a POSIX file specifier, in the format shown in Listing 15-10.


相关资料

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程乐园

请我喝杯伯爵奶茶~!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值