A macOS shell script that recursively converts Apple Pages (.pages) documents
to Microsoft Word (.docx) while preserving the folder structure.
If you have a directory tree full of Pages documents and need Word copies of all of them, this script automates the whole job through Pages itself — no manual "File → Export To → Word" for every file.
- Recursive — finds every
.pagesfile in all subfolders. - High-fidelity conversion — uses the installed Apple Pages application to export, so layouts, fonts, images, and tables are converted by Pages itself.
- Preserves folder structure — optional output directory mirrors the source tree, so documents with the same name in different folders stay separate.
- Safe by default — existing
.docxfiles are skipped unless--forceis used. - Non-destructive — originals are never modified. Documents already open in Pages are left alone.
- Dry-run mode — preview what would be converted without touching anything.
- Handles awkward paths — spaces, quotes, and other special characters in file and folder names.
- Works with both formats — modern single-file
.pagesdocuments and older.pagespackage bundles. - Atomic output — exports to a temporary file first, then moves it into
place, so an interrupted conversion does not leave a partial
.docx.
- macOS with Apple Pages installed (App Store or Apple Creator Studio).
bash(preinstalled on macOS).- Permission for your terminal to automate Pages the first time you run the script (macOS will prompt, or you can enable it under System Settings → Privacy & Security → Automation).
Tested on macOS 15.8.2 with Pages 15.3.1.
The script does not use LibreOffice or third-party converters. Modern Pages files use Apple's IWA format, which Pages itself exports most reliably.
git clone https://github.com/ewweberlin/PagesToDocx.git
cd PagesToDocx
chmod +x pages2docx.shOr simply download pages2docx.sh, make it executable, and run it.
./pages2docx.sh [options] <directory>If <directory> is omitted, the current directory is used.
| Option | Description |
|---|---|
-o, --output DIR |
Write .docx files to DIR, mirroring the source folder structure. By default each .docx is written next to its .pages file. |
-f, --force |
Overwrite existing .docx files. Without this, existing files are skipped. |
-n, --dry-run |
Show what would be converted without converting anything. |
-q, --quiet |
Only print errors and the final summary. |
-h, --help |
Show help. |
Convert everything in place (.docx next to each .pages):
./pages2docx.sh ~/DocumentsConvert into a separate folder, keeping the original directory layout:
./pages2docx.sh -o ~/Documents-Word ~/DocumentsPreview the work first:
./pages2docx.sh --dry-run ~/DocumentsRe-export everything, overwriting old Word files:
./pages2docx.sh --force ~/Documents$ ./pages2docx.sh -o converted "My Documents"
Using /Applications/Pages.app
converting: Reports/2026/Annual Report.pages
converting: Reports/2026/Q1/Budget.pages
converting: Notes/Meeting Notes.pages
Summary: 3 found, 3 converted, 0 skipped, 0 failed
My Documents/ converted/
├── Reports/ ├── Reports/
│ └── 2026/ │ └── 2026/
│ ├── Annual Report.pages │ ├── Annual Report.docx
│ └── Q1/ │ └── Q1/
│ └── Budget.pages │ └── Budget.docx
└── Notes/ └── Notes/
└── Meeting Notes.pages └── Meeting Notes.docx
findrecursively locates every file or package whose name ends in.pages(hidden files and folders are skipped).- For each document, the destination path is calculated — either next to the
source or under
--output, mirroring the relative folder path. - The script records the IDs of documents already open in Pages.
- The source document is opened through LaunchServices (
open -a), the same mechanism Finder uses when you double-click a file. This is more reliable than AppleScript'sopencommand, which can fail or returnmissing valuewhile Pages is launching. - The script waits until a new document ID appears, then exports that exact
document as Microsoft Word to a hidden temporary
.docx. - The temporary file is moved into place, and only the document that was opened by the script is closed. Any documents you already had open are untouched.
Export is wrapped in a 600-second AppleScript timeout to accommodate very large documents.
zsh: permission denied: ./pages2docx.sh
The executable bit is missing. This usually happens when the script was downloaded as a single file instead of cloned. Fix it with:
chmod +x pages2docx.sh
./pages2docx.sh .You can also run the script through bash explicitly:
bash pages2docx.sh .If the error persists, check the file's permissions and extended attributes:
ls -l@ pages2docx.shA folder on an external or network volume mounted with the noexec option can
also cause this. Copy the script into your home folder and try again.
"Operation not permitted" or a modal dialog appears in Pages
Dismiss any Pages dialogs before running the script, and quit Pages if it is in a stuck state. Then try again:
osascript -e 'tell application "Pages" to quit'
./pages2docx.sh .The script reports that the document did not open
If the source file is already open in Pages, opening it again may only focus the existing window instead of creating a new document. Close that document in Pages and retry. The script deliberately does not touch documents that were already open.
Automation permission was denied
Re-enable it under System Settings → Privacy & Security → Automation by allowing your terminal application to control Pages.
Password-protected documents
Pages may show a password prompt that the script cannot answer. Unlock or remove the password first.
Downloaded documents are blocked by Gatekeeper
If the .pages files came from the internet, macOS may quarantine them. Open
one manually and approve it, or clear the quarantine attribute:
xattr -dr com.apple.quarantine /path/to/folderPages is installed under a different name
The script detects Pages by bundle identifier (com.apple.Pages) rather than
by the app's display name, so renamed installations such as
Pages Creator Studio.app are supported.
- macOS only.
- Only
.pagesdocuments are converted — not Numbers or Keynote files. - Conversion fidelity is whatever Pages produces; highly complex layouts may shift when opened in Word.
- Interactive dialogs (password prompts, missing fonts, repair warnings) cannot be handled automatically.
0— all discovered documents were converted or intentionally skipped.- non-zero — at least one conversion failed, or a setup/usage error occurred.
The final summary always reports how many files were found, converted, skipped, and failed.
Issues and pull requests are welcome. Please keep the script dependency-free (other than macOS and Pages) and test changes against a nested folder tree containing spaces in file names.
Released under the MIT License.
Copyright © 2026 ewweberlin.