Is it possible to create and write on a .pages document file via Terminal.app?

I have tried it as explained below but it didn't work. As I understand, I was able to create a .pages file but the binary format wasn't correct.

 touch file.pages  #CREATE THE FILE
 open -a Pages file.pages #OPEN THE FILE WITH PAGES (Pages can not open file.pages)

I have had the same result with following:

ls -l >> file.pages
open -a Pages file.page

I have also tried using different extensions:no extension, txt, rtf, doc, but Pages.app cannot open the file.

How do I do it?

  • A Pages document is not a simple file, but a Zip archive.

  • A Pages document contains much more than just plain text. A blank document is still based on a template, with a set page size and other metadata.

Creating a blank document in Pages creates this structure:

To create a Pages document programatically, use AppleScript to tell Pages to do it for you.

tell application "Pages" to ¬
  save (make new document) in file "Macintosh HD:path:to:folder:Blank.pages"

To run AppleScript from the command line, use osascript.

osascript -e 'tell application "Pages" to save (make new document) in file "Macintosh HD:path:to:folder:Blank.pages"'
| improve this answer | |
  • 1
    Technically a ZIP archive is a file :-) – nohillside Jun 5 '18 at 10:36
  • 1
    @nohillside A very good point! I was intending to write "package" instead of Zip which would definitely not be a file, but then found out Pages changed the default back to single file recently. Thanks for the edit – grg Jun 5 '18 at 10:40
  • 1
    I don't want save the document into an existing file. I want to create a new file, and I cannot do this with this applescript. @grg – federico Jun 5 '18 at 11:22
  • 1
    @federico save (make new document) makes a new document and immediately saves that new document, creating it on disk. There is no existing file for the AppleScript above, you provide a path for the new document to be saved at. – grg Jun 5 '18 at 11:24

You must log in to answer this question.

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