I am currently trying to export an iWork .pages file to a Microsoft Word .docx file with a simple applescript script.
on run {path, fileName}
tell application "Pages"
set theDoc to open (path & "/" & fileName)
set theDocName to name of theDoc
export theDoc as Microsoft Word to file ((path & "/" & theDocName & ".docx") as text)
close theDoc
end tell
end run
I am expecting the document to be exported as a Microsoft Word document however I am receiving the following error:
Pages got an error: The document “1” could not be exported as “/Users/joshgrimmett/Desktop/pages2docs/in/1”. (6)
I managed to export a Pages document to Word with the following script:
Call the script with e.g.
/Users/joshgrimmett/Desktop/pages2docs/in/
andfoo.pages
(or any other Pages-support extension) as arguments. I believe the problem was the usage ofpath
(it is a reserved keyword in AS) as a variable, and not specifying the destination class (Since we’re working with POSIX paths and not aliases, it’sPOSIX file
).