AppleScript – Pages export to PDF fails due to Sandbox permissions

Try adding this line before your exporting step:

open for access file _location

I'm guessing you're using macOS Sierra. This is a known issue. I could only make my code work by using the above step before my export started. Make sure you don't put that line inside a tell block.


You are very close. Edit your export line to look like this:

export front document to file _location as PDF

It's the word "file" that you were missing.

Note: I tried the script again and it did not work, even with the word "file" added. However, while experimenting I found that if I changed this line:

set _location to (_directory as string) & _PDFName

to

set _location to (_directory as string) 

then the script would of course error. But then, if I undid the change, so the line again looked like this:

set _location to (_directory as string) & _PDFName

the script began to work! I am using Pages 6.0.5, macOS 10.12.2.

I can't say what is causing this behavior.