I have a small AppleScript to save a PowerPoint pptx file as PDF from command line. I use the script every 6 months, and last autumn it still worked. But today I run into problems. I updated to 10.14 in the meantime, and I guess there were also quite some Office for Mac updates. But as I have no clue about where this problem is coming from, these can also be completely irrelevant information.
The problem with the script is: When calling the script, it doesn't save a PDF, but sends the file to the default printer.
Here is the already updated, but still not working script:
on run arguments
tell application "Finder"
set src to POSIX file (first item of arguments) as alias
set dest to (second item of arguments) as text
open src
delay 10
tell application "Microsoft PowerPoint"
save in dest as save as PDF
close
end tell
end tell
end run
As there is not much code, and as the script did work before, I have no idea on what is wrong with it now.
@MaxWyss's comment brought me to look at the script from command line. I executed the few steps as arguments via osascript:
$ osascript -e 'tell application "Finder"' -e 'set fileAlias to POSIX file ("file:///Users/me/folder/file.pptx") as alias' -e 'set theOutputPath to ("file:///Users/me/folder/test.pdf") as text' -e 'open fileAlias' -e 'delay 10' -e 'tell application "Microsoft PowerPoint"' -e 'save in theOutputPath as save as PDF' -e 'end tell' -e 'end tell'
281:320: execution error: Microsoft PowerPoint got an error: Parameter error. (-50)
I'm a little surprised about the error message, so I tried to run the script again:
$ osascript pptx2pdf.scpt file:///Users/me/folder/file.pptx test.pdf
pptx2pdf.scpt: execution error: Microsoft PowerPoint got an error: Parameter error. (-50)
I don't know why I overlooked this error. I guess it is due to the many things I changed in the script. However, this is the error message, which, unfortunately, still leaves me without a clue, as the slides still get sent to the printer queue.
Best Answer
It took me a few hours to come up with a solution that works in my environment. Please note that some elements need internationalization like "Vorschau" or "Sichern". This is a german solution working with PowerPoint for Mac 16.16.27 on macOS HighSierra 10.13.6.
I had to heavily debug things with Script Debugger ($99 well spent ..) to get things working. Please note how Preview is used for the actual PDF saving. I tried doing this from Powerpoint but it was unreliable.