MacOS X: How to convert a number of Pages documents to Word format

Ran into this a couple of weeks ago. If you have someone who ran Pages and needs to convert their library of documents to Word format, do the following. This requires iWork ‘09.

  1. Open script editor and paste in the script listed below.
  2. Save this script as an application
  3. Drag all your Pages documents on top of the script application. Word documents will be created in the same directory as the original document.
  4. Enjoy!

The script:

on open theFiles

tell application “System Events”

if process “Pages” exists then

display dialog “whoops, please close Pages before running droplet!”

end if

end tell

tell application “Archive Utility”

activate

delay 1

close front document

set theType to “doc”

set s to theType as string

set theLocation to choose folder

set theLocation to theLocation as string

repeat with aFile in theFiles

open aFile

set asType to “Microsoft Word 97 - 2004 document”

set docName to name of front document

-- Remove .pages extension.

set prevTIDs to AppleScript’s text item delimiters

set AppleScript’s text item delimiters to “.pages”

-- Add .doc extension.

set docNameNew to first text item of docName & “.doc”

set AppleScript’s text item delimiters to prevTIDs

-- Save file to Desktop.

set docPathAndName to theLocation & docNameNew

save front document as asType in docPathAndName

try

close front document saving no

end try

end repeat

quit

end tell

end open