Created
November 3, 2025 16:46
-
-
Save philsinatra/0d331a59c2e6109e890c134920b00a55 to your computer and use it in GitHub Desktop.
Pages to DOCX automation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use scripting additions | |
| set pagesFolder to choose folder with prompt "Select the folder containing your Pages documents:" | |
| set outputFolder to choose folder with prompt "Select the folder to save the exported DOCX files:" | |
| tell application "Finder" | |
| set pagesItems to every file of pagesFolder whose name extension is "pages" | |
| end tell | |
| if (count of pagesItems) is 0 then | |
| display alert "No .pages files found." buttons {"OK"} | |
| return | |
| end if | |
| tell application "Pages" | |
| activate | |
| repeat with i from 1 to count of pagesItems | |
| set aFile to item i of pagesItems | |
| try | |
| open aFile | |
| delay 1 | |
| repeat until (count of documents) ≥ 1 | |
| delay 0.5 | |
| end repeat | |
| set theDoc to document 1 | |
| set docName to name of theDoc | |
| if docName ends with ".pages" then | |
| set docNameWithoutExtension to text 1 thru -7 of docName | |
| else | |
| set docNameWithoutExtension to docName | |
| end if | |
| set outputFilePath to (outputFolder as text) & docNameWithoutExtension & ".docx" | |
| -- FIXED: Export at application level | |
| export theDoc to file outputFilePath as Microsoft Word | |
| close theDoc saving no | |
| on error errMsg number errNum | |
| display dialog "Error with " & (name of aFile) & ":" & return & errMsg & " (" & errNum & ")" buttons {"OK"} | |
| end try | |
| end repeat | |
| end tell | |
| display alert "Export Complete!" message "All files processed." buttons {"OK"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment