使用Applescript打开MS Powerpoint 2016文件
我正在尝试使用AppleScript自动转换MS PowerPoint(15.30版)2016文件.我有以下脚本:
I am trying to automate the conversion of a MS PowerPoint (Version 15.30) 2016 file using AppleScript. I have the following script:
on savePowerPointAsPDF(documentPath, PDFPath)
tell application "Microsoft PowerPoint"
open alias documentPath
tell active presentation
delay 1
save in PDFPath as save as PDF
end tell
quit
end tell
end savePowerPointAsPDF
savePowerPointAsPDF("Macintosh HD:Users:xx:Dropbox:zz yy:file.pptx", "Macintosh HD:Users:xx:Dropbox:zz yy:file.pdf")
此脚本可以正常工作,除了:
This script works fine except:
- 第一次运行它,我会看到授权访问"对话框.
- 我每次运行它时,都会看到一个对话框,其中显示:文件名已被移动或删除."
单击所有这些对话框后,它将正常工作.我尝试使用POSIX文件名,但没有成功.我无法在其中留出空间来工作.
Once I click through all these dialog boxes, it works fine. I have tried using POSIX file names, but with no success. I could not get a path with a space in it to work.
以下与Excel一起解决了第一个问题,但似乎不适用于PowerPoint:
The following worked with Excel for solving the first problem, but does not seem to work with PowerPoint:
set tFile to (POSIX path of documentPath) as POSIX file
总而言之,我只是尝试使用AppleScript在Mac上使用PowerPoint 2016打开PowerPoint文件.路径和文件名中可能包含空格和其他macOS允许的非字母数字字符.
In summary, I am just trying to use AppleScript to open a PowerPoint file using PowerPoint 2016 for the Mac. The path and the filename may contain spaces and other macOS allowed non-alphanumeric characters in them.
关于如何解决这些问题的任何建议?
Any suggestions on how can I solve these problems?
Powerpoint 的 save 命令需要一个现有文件来避免出现问题.
The save command of Powerpoint need an existing file to avoid issues.
为避免 open 命令出现问题,请将路径转换为 alias对象
(该命令必须位于" tell应用程序
之外"'块,像这样:
To avoid issue with the open command, convert the path to an alias object
(the command must be outside of the 'tell application
' block, like this:
on savePowerPointAsPDF(documentPath, PDFPath)
set f to documentPath as alias -- this line must be outside of the 'tell application "Microsoft PowerPoint"' block to avoid issues with the open command
tell application "Microsoft PowerPoint"
launch
open f
-- ** create a file to avoid issues with the saving command **
set PDFPath to my createEmptyFile(PDFPath) -- the handler return a file object (this line must be inside of the 'tell application "Microsoft PowerPoint"' block to avoid issues with the saving command)
delay 1
save active presentation in PDFPath as save as PDF
quit
end tell
end savePowerPointAsPDF
on createEmptyFile(f)
do shell script "touch " & quoted form of POSIX path of f -- create file (this command do nothing when the PDF file exists)
return (POSIX path of f) as POSIX file
end createEmptyFile
savePowerPointAsPDF("Macintosh HD:Users:xx:Dropbox:zz yy:file.pptx", "Macintosh HD:Users:xx:Dropbox:zz yy:file.pdf")