DEV Community


Markdown to Pages format conversion

cookrdan profile image Dan 惻1 min read

I write a lot of things in Markdown and use Pandoc for a number of things. I haven't been able to find a way to convert markdown to pages format. At times I need to send a document in either docx or pages. It's easier in pages.

Pandoc of course is essential:

pandoc -o document.docx 

It'd be great if I could get .docx to .pages conversion working in the command line somehow. So I fiddled. For too long.

Apple Script is able to accomplish this - and here is the basic thing of it:

set old_doc to POSIX file "/Users/username/path/to/docx/file.docx" as string

set new_doc to POSIX file "/Users/username/path/to/pages/file.pages" as string

tell application "Pages"
    set thisDoc to open old_doc
    save thisDoc in file new_doc
    close thisDoc
end tell

Note: if you don't tell Pages to activate then this process will probably remain hidden behind other open windows - it's also quite fast

I have yet to finish this little project. I plan to script it out more using osascript so that I will just be able to type mdtopages in my terminal and end up with document.pages.

Discussion (1)

Editor guide
brandelune profile image
Jean-Christophe Helary

Are you aware of the textutil command ? For some reason it does not support pages but it can convert to and from "txt, rtf, rtfd, html, doc, docx, odt, wordml, or webarchive".