Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

You don't have permission

I use sierra and pages latest version.

I tried applescript to export to docx and text file.

But I have error message "You don't have permission".

Other appescripts that I downloaded from some sites have same problem.

I thought Pages has a problem. I checked "sharing and permission" on the pages info. But no problem.


Here example.


-- p2word.applescript

-- Batch convert Pages documents to MS Word. Word documents written to original

-- path and filename. (e.g. /Users/viking/Desktop/foo.pages /Users/viking/Desktop/foo.docx)

-- Aug 7, 2016: Tested on OS X 10.11.6 with Pages v5.6.2. Requires Pages v5, or later.

-- Version 1.2, VikingOSX, Apple Support Community, No warranties expressed or implied.

usescripting additions

property MSWord : {docx:"docx", doc:"doc"}

propertyWord_type : (docxofMSWord)

property Pages : {"com.apple.iwork.pages.sffpages", "com.apple.iwork.pages.pages"}

property fileCnt : 0 as integer


-- Double-click application for interactive mode

on run

try

set fileObjects to (choose filewith prompt "Get File" of typePageswithmultiple selections allowed)

openfileObjects

on error errmsg number errnbr

my error_handler(errnbr, errmsg)

end try

return

end run


-- drag & drop file(s) and folder(s) mode when compiled as an Application

onopenfileObjects

-- can only run this with Pages v5 or later

tell application "Pages" to set its_version to version of it

if its_version is less than "5.0" then

display alert "Requires Pages v5 or later" as critical giving up after 10

return

end if

repeat with aFile in fileObjects

tell application "System Events" to set {akind, pf} to {kind, package folder} of aFile

-- a package folder will also have a kind of "Folder"

if akind contains "Folder" and pf is false then

tell application "Finder"

set pages_list to (every item in entire contents of folder aFile whose kind is "Pages Publication") as alias list

end tell

repeat with pages_fileinpages_list

export_file(pages_file, Word_type)

end repeat

else if akind contains "Pages Publication" then

export_file(aFile, Word_type)

end if

end repeat


if fileCnt > 0 as integer then

display notification "Files exported to Word: " & (fileCnt as text) ¬

with title "Pages v5 File Export Facility" subtitle "Processing Complete"

set fileCnt to 0 as integer

end if

-- ensure that Pages quits when done

tell application "Pages" to if it is running then quit

return

end open


onexport_file(theFile, doc_ext)

tell application "System Events" to set package_folder to package folder of theFile as boolean

if false is in package_folder then

-- single file format

set exportDocument to text 1 thru -6 of (theFile as text) & doc_ext

else

-- package folder names end in ':' so trim that character from filename

set exportDocument to text 1 thru -7 of (theFile as text) & doc_ext

end if


tell application "Pages"

try

with timeout of 1200 seconds

set mydoc to open theFile

exportmydoctofileexportDocumentasMicrosoft Word

end timeout

closemydocsavingno

set fileCnt to (fileCnt + 1) as integer

on error errmsg number errnbr

myerror_handler(errnbr, errmsg)

set fileCnt to 0 as integer

tell application "Pages" to if it is running then quit

return

end try

end tell


-- Overriding Pages default behavior to hide the document extension on export

tell application "Finder"

set extension hidden of (file exportDocument as alias) to false

end tell

return

endexport_file


onerror_handler(nbr, msg)

return display alert "[ " & nbr & " ] " & msg as critical giving up after 10

enderror_handler

--

--

macOS Sierra (10.12.2), null

Posted on Dec 30, 2016 10:27 PM

Reply
Question marked as Best reply

Posted on Feb 1, 2017 2:59 AM

This issue is fixed by experts.

AppleScript+Pages: Export command always fails with permission error


Just add this

close access (open for accessexportDocumentFile)

Thank you. Rsgranne and VikingOSX.

11 replies

Dec 31, 2016 3:32 AM in response to bjh333

I can't work out what the problem is, but I have found this other script by VikingOSX that works fine (you can read the original discussion here: AppleScript+Pages: Export command always fails with permission error ). It doesn't do batches, but you don't say whether you need that or not.


property pages_type : {"com.apple.iwork.pages.pages", "com.apple.iwork.pages.sffpages"}

property labelColor : {none:0, orange:1, red:2, yellow:3, blue:4, purple:5, green:6, gray:7}


set afile to ¬

(choose file with prompt "Choose Pages documents" of type pages_type ¬


default location (path todesktop folder) ¬

without invisibles)


set exportDocumentFile to text 1 thru (offset of ".pages" in (afile as text)) of (afile as text) & "docx"

-- log exportDocumentFile

try

tell application "Pages"


openafile


delay 2

with timeout of 1200 seconds


export front documenttofileexportDocumentFileasMicrosoft Word

end timeout


close front documentsavingno

end tell

on error msg number enbr


display alert "[ " & enbr & " ] " & msggiving up after 8

tell application "Pages" to if it is running then quit

end try


tell application "Finder"

set extension hidden of fileexportDocumentFile to false


-- set label index of file exportDocumentFile to blue of labelColor

end tell

Dec 31, 2016 5:04 AM in response to bjh333

The above code works correctly on El Capitan 10.11.6 with Pages v5.6.2. On macOS Sierra 10.12.2, it breaks on the Pages v6.0.5 export line because it is not seeing an extension on the exported filename, and raises a permission error. The Script Editor log however, shows a proper filename.docx on the export line before it blows up. A contradiction.


I will look into this, and determine if it is fixable, or a bug report. The Pages scripting dictionary has not changed for export enums from El Capitan, and neither has the version of AppleScript.

Dec 31, 2016 6:00 AM in response to VikingOSX

Changing the name of the exported document to a different name than the opened Pages document still results in the same problem. This is a Desktop folder that has no extended attributes on it, and everything else, including Pages v6.0.5 has read and written to it countless times. It has the standard permissions of a folder created on the Desktop (e.g. 755).


The specific error message follows, and it doesn't matter which Pages document is attempted, as I have tried several which do work on this same code run on El Capitan.

User uploaded file

Investigation continues, but no quick fix in sight. This is standard export syntax for Pages v5 and later.


I have another AppleScript that exports Pages documents to PDF, and it is also breaking on macOS Sierra 10.12.2 and Pages v6.0.5 with the same error.

Dec 31, 2016 7:11 AM in response to VikingOSX

Update.


The same AppleScript code that works correctly with El Capitan 10.11.6 and Pages v5.6.2 — fails with identical errors with these Pages versions {5.6.2, 6.0.0, 6.0.5} on macOS Sierra 10.12.2. This would suggest there is a problem that I cannot code around, and increasingly, it appears to be collateral damage from at least this version of Sierra, AppleScript, and the Pages scripting dictionary implementation.


Using an AppleScript to save a Pages '09 document as a PDF into the same folder as the failures above — worked correctly.

You don't have permission

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.