I'm trying to create an Automator workflow to export selected Pages documents to PDF. So far, everything goes well, except for the final export step.

on run {input, parameters}
    repeat with _document in input

        tell application "Finder"
            set _directory to get container of file _document

            set _documentName to name of _document
            if _documentName ends with ".pages" then ¬
                set _documentName to text 1 thru -7 of _documentName

            set _PDFName to _documentName & ".pdf"
            set _incrementIndex to 1
            repeat until not (exists file _PDFName of _directory)
                set _PDFName to ¬
                    _documentName & "-" & (_incrementIndex as string) & ".pdf"
                set _incrementIndex to _incrementIndex + 1
            end repeat

            set _location to (_directory as string) & _PDFName
        end tell

        --set _location to (POSIX file of _location)

        tell application "Pages"

            open _document

            with timeout of 1200 seconds
                export front document to file _location as PDF
            end timeout

            close front document

        end tell

    end repeat
    return input
end run

This gives me a Sandbox permissions error.

error   17:49:38.117966 +0100   sandboxd    SandboxViolation: Pages(3846) deny file-write-create /Users/brunoscheele/Desktop/Test.pdf
Violation:       deny file-write-create 

After reading up on it here, it looked like I could fix this by changing _location to a POSIX file.

So I added;

--set _location to (POSIX file _location)

However, that then gives me the error:

Pages got an error: "macOS:Users:brunoscheele:Desktop:Test.pdf" could not be interpreted as a file URL.

Using export front document to (POSIX file _location) as PDF gives me the same error.

Does anyone know how to set the _location properly, so you don't run into permission issues?

  • Please include the macOS version in your question.
    – Chris Page
    Feb 4, 2017 at 23:02
  • @ChrisPage The latest, always. But thanks for chiming in! And there was an answer in the meantime, check it below. Feb 18, 2017 at 16:19

3 Answers 3


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


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.

  • Thanks for answering! Sadly, that was actually what gives the current permission errors. The script I originally pasted was after a couple of experiments, which is why I omitted it accidentily. See the updated original. Looks like it's a new error, considering this tweet; twitter.com/MACAUTOMATION/status/810997383672655872 . Any other insights? Jan 20, 2017 at 9:55
  • I edited my answer to show how I made the script work. Maybe it will work for you the same way. Jan 23, 2017 at 0:44
  • "could not be interpreted as a file url" on both os x 10.2.2 and 10.2.3
    – ina
    Feb 7, 2017 at 1:38

I had a similar issue with a script I was working on. It does indeed seem to be permissions related. The way I got round it was by creating the PDF inside the Pages file package. So, if your Pages file is at:

Macintosh HD:Users:Admin:Desktop:myfile.pages

...then create your PDF at:

Macintosh HD:Users:Admin:Desktop:myfile.pages:myfile.pdf

There's a code sample of the code where I ran into this problem, and a sample of how I solved it here:


Hope that helps!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .