Trying to batch convert pages to plain text but I keep running into issues with file permissions. (Using Sierra 10.2.3 after upgrading from 10.2.2)

filename could not be exported. You don't have permission.

Two methods so far:

on run
    tell application "Finder"
        set mfolder to "Macintosh HD:Users:me:Documents:convertme:"
        set theFiles to name of every file of folder mfolder
    end tell
    set theFolder to "Macintosh HD:Users:me:Documents:converted:"
    tell application "Pages"
        repeat with aFile in theFiles
            open aFile
            set sourceFolder to POSIX path of aFile
            set newsourceFolder to characters 1 thru -8 of sourceFolder as string
            set theFolder to newsourceFolder & ".txt"
            export front document to POSIX file theFolder as unformatted text
            close front document
        end repeat
    end tell
end run

Also tried with Automator: on Ask for Finder Item

function run(input, parameters) {
    inFile  = Path( input );
    outFile = Path( input.toString().replace(/\.[^\.]+$/, '.pdf') );
    pages    = Application('Pages');
    document = pages.open( inFile );
    pages.export(document, {to: outFile, as: 'PDF'});
    pages.close(document, {saving: 'no'});
    return outFile;

Permissions on folder set to: everyone read&write

  • Do mfolder and theFolder already exist and if so do you have permission to read/write to them? That said, why are you creating generic folders directly under Users, that's a poor practice! You should set the folder to read from and write to somewhere within your own Home folder as that should avoid permission errors. (That's assuming you have permission to read the source files in the first place.) – user3439894 Feb 6 '17 at 15:44
  • oh, i'm actually creating them as a long sub folder under Users but truncated that for simplicity.. – ina Feb 6 '17 at 18:08
  • i just checked and made sure everyone had read&write permissions... still getting the same error – ina Feb 6 '17 at 18:12
  • Did you check the access rights on the pages files as well? How do the filenames look like, are there any non-ASCII characters in it (any umlauts or other utf8 characters)? – nohillside Feb 8 '17 at 8:29
  • regular ascii files... tried with others too... apparently you are supposed to use close access as indicated below – ina Feb 8 '17 at 22:46

This script works for me, tested on MacOS Sierra and Pages Version 6.0.5

set mfolder to "Macintosh HD:Users:me:Documents:convertme:"
set destFolder to "Macintosh HD:Users:me:Documents:converted:"

tell application "Finder" to set theNames to name of files of folder mfolder

tell application "Pages"
    repeat with aName in theNames
        set theDoc to open ((mfolder & aName) as alias)
        set newFile to destFolder & (text 1 thru -7 of aName) & ".txt" -- concat destFolder and the name without the ".pages" extension 
        my makenewFile(newFile)

        export theDoc to file newFile as unformatted text
        close theDoc
    end repeat
end tell

on makenewFile(thePath)
    close access (open for access thePath)
    -- delay 0.5 -- use the delay command, If you still have a permission issue,  increase the number of seconds
end makenewFile
  • cool! apparently this gets by the weird permissions issue - 'close access (open for access thePath)' – ina Feb 8 '17 at 9:11

You must log in to answer this question.

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