Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Automator to change pages to word

I have very many (350) pages documents existing in a set of nested folders

anmd i would like to change them all to word documents (as the person I need

to send these to has a PC and Office, not Pages)


How to do? I have never used automator before

powerbook 1.5GHz, Mac Mini core Duo, LaCie 250GB rugged ext. HD, Mac OS X (10.6.7), Time Capsule 1TB, AEX, iMac 27" 3.06 core 2 duo

Posted on May 25, 2012 5:14 PM

Reply
9 replies

May 25, 2012 5:28 PM in response to twtwtw

Rich text, with a very few photos (so few, in fact, that I could afford to lose them)---they are recipe

collections taken from different sources (in AppleWorks, no less, then converted to Pages)


I don't know how they were made, it is a collection I have been given to "curate" and make accesible

to different people with different systems.

May 25, 2012 6:12 PM in response to David52

well, a quick google turned up this thread. I've tweaked the applescript I found there a bit. Open the applescript editor, paste in the following code, and save it as an application. It will create a new droplet app; drag and drop your files onto it and they'll be converted. You're going to have to let it work. Pages needs to be frontmost while the script runs, which means you won't be able to do anything else until it's done.


I suggest you convert them to pdf files rather than word files (I've set it up to do pdf by default). Everyone can open pdfs (not everyone has Office installed on their machine), pdfs will deal with the pictures and formatting properly, and (unlike Word) pdfs can't be edited easily.


on openfileList


-- change this line to the extension of whatever output file you want.

set newFileExt to "pdf"


-- change this line to point to the folder you want output files to go to. preset to desktop folder.

set savePath to path todesktop folderastext


repeat with thisFile in fileList

set thisFile to thisFile as text

tell application "System Events" to tell disk item thisFile

set {fileName, fileExt} to {get name, get name extension}

end tell

set newName to text 1 thru -(1 + (count of fileExt)) of fileName

tell application "Pages"

activate


-- tricky: apparently Pages is smart enough to create the correct file type based on the extension

set newFileName to savePath & newName & newFileExt

set x to makenewdocumentwith properties {path:newFileName}

openthisFile

savedocument 1 infilenewFileName

close every windowsavingno

end tell

end repeat

end open

May 26, 2012 7:30 AM in response to David52

Hi,


You can save as (PDF or Word) without (make new document) , Pages can remain in the background


--------------------------------------------------------

onopenfileList

-- change this line to point to the folder you want output files to go to. preset to desktop folder.

setsavePathtopath todesktop folderastext

tell application "Pages" -- iWork 09

repeatwiththisFileinfileList

try

tell (open thisFile)

set newName to my getDocName(get name)

save as "SLDocumentTypePDF" in file (savePath & newName) -- Pages automatically adds the extension

close saving no

end tell

end try

end repeat

endtell

endopen


ongetDocName(t)

if t ends with ".pages" then return text 1 thru -7 of t

return t

endgetDocName

--------------------------------------------------------


If you want to save as Word document, replace in the script "SLDocumentTypePDF" by "Microsoft Word 97 - 2004 document"

May 26, 2012 7:49 AM in response to Jacques Rioux

Jacques - nice. Just out of curiosity, where is the SLDocumentTypePDF keyword documented? I found another help page that lists out the keywords for pdf, doc, plain text, rich text, and a rich text bundle (SLDocumentTypePDF, SLDocumentTypeMSWord, SLDocumentTypePlainText, SLDocumentTypeRichText, and SLDocumentTypeRichTextBundle), but I don't know if that's the complete list.

Jul 10, 2012 9:12 AM in response to Jacques Rioux

For some reason, this approach doesn't (always?) work for me, so I combined both approaches above, and added in a bit of logic to make both files share the same modification date. Oh, and each file will be exported to the folder it is in.



on open fileList
      -- change this line to point to the folder you want output files to go to.  preset to desktop folder.
      -- set savePath to path to desktop folder as text
          tell application "Pages" -- iWork 09
                    repeat with thisFile in fileList
                              set curName to name of (info for thisFile) as text
                              set savePath to my dirName(thisFile, true) as text
                              set newName to my getDocName(savePath & curName)
                              set curName to (savePath & curName)
                              set exportFile to newName
                              set openDocument to open thisFile
                              try
                                        tell openDocument
                                   save as "SLDocumentTypeMSWord" in file exportFile -- Pages automatically adds the extension
                                   close saving no
                                        end tell
                              on error error_message number error_number
                                --display dialog "Error saving " & exportFile & return & return & error_message buttons {"ok"} default button 1
                                -- tricky: apparently Pages is smart enough to create the correct file type based on the extension
                                        set exportFile to exportFile & ".doc"
                                        set x to make new document with properties {path:exportFile}
                                        try
                                     save openDocument in file exportFile
                                        on error error_message number error_number
                                     display dialog "Error saving " & exportFile & return & return & error_message buttons {"Cancel"} default button 1
                                        end try
                                close x saving no
                                close openDocument saving no
                                -- get the POSIX paths for the 2 files:
                                        set exportFile to POSIX path of exportFile
                                        set curName to POSIX path of curName
                                -- construct and execute a command to make the 2 files share the same modification date.
                                do shell script ("sh -c 'touch -r " & curName & " " & exportFile & "'")
                              end try
                    end repeat
          end tell
end open



on getDocName(t)
          if t ends with ".pages:" then return text 1 thru -8 of t
          if t ends with ".pages" then return text 1 thru -7 of t
          return "bla"
end getDocName



on dirName(thePath, wantPath)
          set thePath to (thePath as text)
          if thePath contains ":" then
                    set pathDelim to ":"
          else
                    set pathDelim to "/"
          end if
          set saveDelim to AppleScript's text item delimiters
          set AppleScript's text item delimiters to {pathDelim}
          set pathAsList to text items of thePath
          if the last character of thePath is pathDelim then
                    set idx to (the number of text items in thePath) - 2
          else
                    set idx to -2
          end if
          if wantPath then
                    set folderName to ((text items 1 through idx of pathAsList) as text) & pathDelim
          else
                    set folderName to item idx of pathAsList
          end if
          set AppleScript's text item delimiters to saveDelim
          return folderName
end dirName

Automator to change pages to word

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.