So if you read this blog you already know that I have pretty much come to the decision that my next computer will not be a Mac. I love my old MacPro 4,1 but it is getting long in the tooth, and I haven’t even been able to do the Firmware Upgrade to get it to 5,1, so the next OS Sierra will not work on my current MacPro as it will only work on a 5,1 (I haven’t tried putting in my old video card before the upgrade, which might help, but it looks like El Capitan makes it harder).
Unfortunately in 2007 I moved over to Pages to do my invoices, resumes and cover letter. Now you can individually export your documents to the modern word format docx, but I am talking hundreds and hundreds of files that I may want to access at some point, so I wanted a way to batch those files.
This requires applescript, and while I used to be OK at Applescript all those skills have since gone away.
A quick google search showed one page dedicated to scripting the iWorks suite, and it is iWorkAutomation. Specifically there is a script to Export to Word, but it is not a batch export, just a single use, and so not of use to me, except for stealing some of it’s commands.
So then I went back to the old faithful applescript forums MacSpripter, and did a search. And I found an awesome script from Yvan Keonig, which automates the process, allowing you to pick a folder with you pages documents and then chose a destination folder, and it batch converts to PDF files.
Luckily my limited Applescript skills and the fact that the script was so well written, let me use the Microsoft Word commands from iWork Automation and combine them to make a script to convert to Word documents.
Just copy this script and paste it into Script Editor and run the script. You can also save the script to your scripts folder.
set theSourceFolder to (choose folder with prompt “Select a folder whose files you wish to convert to word:”)tell application “Finder”set filesArray to every file of theSourceFolder whose name extension is “pages”end tellset theDestinationFolder to (choose folder with prompt “Select a folder where you want the converted files to be placed: “)tell application “Pages” to activaterepeat with aFile in filesArraytell application “Finder”set fileAlias to aFile as aliasset fileName to name of fileAliasset fileExtension to name extension of fileAliasend tellset theOriginalName to fileName— remove extensionset prevTIDs to AppleScript’s text item delimitersset AppleScript’s text item delimiters to “.” & fileExtension as stringset fileName to first text item of fileNameset AppleScript’s text item delimiters to prevTIDs— prepare desktop folder path and nameset docPathAndName to (theDestinationFolder as text) & fileName & “.docx” # EDITEDtell application “Pages”— open the fileset targetDocument to open fileAlias — EDITED : was aFile which is a Finder reference, not what Pages requiresrepeat 10 times # I added a loop which may be useful if the original document is very longtryexport targetDocument to file docPathAndName as Microsoft Wordexit repeaton errortell me to delay 0.5end tryend repeat— close itclose targetDocument saving noend tellend repeattell application “Pages” to quitdisplay dialog “Done!”
Awesome, now I have batch updated all my pages documents to Word documents. Sure the formatting needs some updating, but at least they will all work on a PC!