Batch convert .pages files to .doc /.docx files

Hello everyone, I'd like to know if there is a way to batch convert .pages files to .doc or .docx files...


I'm using latest macOS, and latest Pages and latest Word. I'm not very good at using scripts etc... sorry.

I would like to convert many files located in a folder and generate Word documents from every Pages document and locate that new Word document in the same folder that Page document was located.


Is there any program / application that can help me?! thank you and have a nice day.

Posted on Feb 18, 2018 12:02 PM

Reply
4 replies

Feb 19, 2018 5:02 AM in response to lea-law

The only thing wrong with my previous post is how one runs the script interactively from the Script Editor. Step 2C should have said control+command+R, and not shift+command+R. I copied the posted code, and pasted back into Script Editor, where it ran correctly to export a Pages document to Word .docx.


The code will not work with Pages '08, '09, or Pages v5.0 thru 5.2.2. It should work on Pages v5.5.3 on Yosemite. I know it works on Pages v5.6.2 (El Capitan), and on macOS 10.13.3 with Pages v6.3.1 where it was tested.


I have substantial patience. If your operating system and version of Pages complies with paragraph 2, then we can get the script to work for you.


Let's start by the selection of the script code in my post. Because the code scrolls, you click preceding the first line of it, and then drag downward until you get to the bottom edge of the visible code. Then, without releasing your click, you drag against the lower boundary of the code (perhaps once or twice), and scrolling with continued selection will occur until you reach the end of the complete script code. Then you copy to the clipboard, and then paste into Script Editor. Without full selection of the code, nothing will work in the Script Editor.


Tell me if you had a problem with paragraph four and the selection process. The last three lines that should appear in the Script Editor are:


on error_handler(nbr, msg)

return display alert "[ " & nbr & " ] " & msg as critical giving up after 10

end error_handler

Feb 18, 2018 1:03 PM in response to lea-law

I have two types of Pages to Word .docx batch (AppleScript) applications. One is drag and drop, the other is interactive, and will process the file/folder that you select. I haven't tested High Sierra 10.13.3, but prior releases of High Sierra simply broke drag and drop functionality that had worked perfectly in Sierra and El Capitan (with identical code).


Let me do some testing with 10.13.3 to see if Apple has fixed the drag/drop issues, and then I will post whichever of the types of script that still works. You do not need to learn AppleScript.

Feb 18, 2018 3:40 PM in response to lea-law

I have settled on an interactive form of a batch processing solution, because it tests correctly on both El Capitan 10.11.6 (Pages v5.6.2) and on High Sierra 10.13.3 (Pages v6.3.1). The solution that I have provided, when run, will prompt you with a custom file chooser that will allow you to select multiples of Pages documents, and/or folders containing the same. Exported Word documents are written to the original location with a .docx extension.


Although this is an AppleScript (and some Objective-C) code, it is thoroughly tested, and you won't need to beome a programmer. Think of it as that black box with a switch where the hand comes out and switches it off. All you need to do is copy the source code into the Script Editor, save the source text, and then save as a Desktop application that you double-click to run. When the application is done, it will provide a dialog of processed file count.


Steps:

  1. The code is in a scrollable window, so scroll up and down, side to side, to see all of the code. Now, click in the upper-left most corner, and drag down to the select all of the window source code. Copy to the clipboard.
  2. From the Dock, click Launchpad : Other : Script Editor
    1. Paste the clipboard content into Script Editor.
    2. Click the compile button in the Toolbar to transform the monotone purple text into different colors. That is your clue that you copied all of the original code. Otherwise, things remain monotone and an error appears. You will need to revisit copying and pasting all of the code.
    3. Do not click the Run button. Ever. This code requires you to press shift+command+R to run it interactively in the Script Editor.
    4. Save the original AppleScript source.
      1. File menu : Save…
      2. File Format: Text
      3. Name: arbitrary (e.g. pages2word.applescript)
      4. Leave everything else on the Save panel as default, and Save.
    5. Save as an Application.
      1. Option : File menu : Save As…
      2. File Format: Application
      3. Location: Desktop
      4. Hide Extension: √
      5. Leave everything else on the Save As… panel as default, and Save.
    6. Quit Script Editor
  3. Double-click the application on your Desktop to open the selection window and start processing.


Code (scrollable window):


-- pages2docx.applescript -- Interactive application that allows one to select combinations of Pages documents, -- and/or folders containing them. Exported word documents are written to original -- Pages document location with only the extension changed to docx. -- Revision 1.3, Tested on OS X El Capitan 10.11.6, macOS High Sierra 10.13.3 -- VikingOSX, 2018-02-18, Apple Support Communities use framework "Cocoa" use AppleScript version "2.4" -- Yosemite or later use scripting additions property app_icon : "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/MultipleItemsIcon.icns" property valid_document : {"com.apple.iwork.pages.sffpages", "com.apple.iwork.pages.pages"} property valid_kind : {"Pages Publication", "Pages document"} property default_folder : POSIX path of ((path to desktop folder) as text) property selected_items : {} property HFS : "HFS" property POSIX : "POSIX" property exportFormat : ".docx" on run -- user interactive via double-click on application set fileList to {} set dropped_items to {} -- check we are running in foreground. Prevents hanging Script Editor when run. -- can use control+command+R to override the above. if not (current application's NSThread's isMainThread()) as boolean then display alert "This script must be run from the main thread, or with control+commmand+R from the script editor" buttons {"Cancel"} as critical error number -128 end if try -- allow user to select multiples of Pages documents and/or containing folders set fileList to get_files_folders(HFS) -- guard against user not selecting anything and clicking "Select" if (item 1 of fileList) is equal to (default_folder as POSIX file) then display alert "Warning!" message "Actually choose something. Don't just click Select." as critical giving up after 10 return end if -- we must construct alias POSIX file items beforehand if (fileList as text) contains ":" then repeat with ndx in fileList copy (ndx as alias) to the end of selected_items end repeat else if (fileList as text) contains "/" then repeat with zdx in fileList copy (zdx as POSIX file as alias) to the end of selected_items end repeat end if -- pass selected files/folders to selection handler open selected_items on error errmsg number errnbr my error_handler(errnbr, errmsg) my cleanup() end try return end run on open selected_items -- main processing global fileCnt set fileCnt to 0 as integer repeat with anItem in selected_items try tell application "System Events" to set {akind, apkg} to {kind, package folder} of anItem if akind contains "Folder" and apkg = false then tell application "Finder" set docList to (every item in entire contents of folder anItem where valid_kind contains kind of it) as alias list end tell repeat with afile in docList export_file(afile) end repeat else if valid_kind contains akind then export_file(anItem) end if on error errmsg number errnbr my error_handler(errnbr, errmsg) my cleanup() return end try end repeat -- completion dialog my report_complete(fileCnt, exportFormat) my cleanup() return end open -- handlers on export_file(theFile) global fileCnt tell application "Finder" to set name_ext to name extension of theFile -- preserve original file location while replacing Pages with Word extension set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ".pages"} set temp to text items of (theFile as text) set AppleScript's text item delimiters to TID set exportDocument to (first item of temp) & exportFormat -- Fix for Sierra/Pages v6 write permission error on export` close access (open for access exportDocument) tell application "Pages" try set mydoc to open theFile with timeout of 1200 seconds export mydoc to file exportDocument as Microsoft Word end timeout close mydoc saving no on error errmsg number errnbr my error_handler(errnbr, errmsg) my cleanup() return end try end tell -- Force Word document extension displayed tell application "Finder" set extension hidden of (file exportDocument as alias) to false end tell set fileCnt to (fileCnt + 1) as integer return end export_file on get_files_folders(fileFormat) -- AppleScript/Objective-C chooser for multiple files and folders set returnCode to 0 as integer set openPanel to current application's NSOpenPanel's openPanel() tell openPanel its setFloatingPanel:true -- pop over all other windows its setFrame:(current application's NSMakeRect(0, 0, 720, 525)) display:yes its setTitle:"File Chooser" its setMessage:"Choose Pages documents and/or Folder(s) containing Pages documents:" its setPrompt:"Select" its setAllowedFileTypes:valid_document its setCanChooseDirectories:true its setCanChooseFiles:true its setTreatsFilePackagesAsDirectories:false its setAllowsMultipleSelection:true its setDirectoryURL:(current application's class "NSURL"'s fileURLWithPath:default_folder) set returnCode to its runModal() end tell if returnCode is (current application's NSFileHandlingPanelCancelButton) then error number -128 if fileFormat is HFS then -- set thePOSIXpaths to (openPanel's |URL|()'s valueForKey:"path") as list set theFilePaths to openPanel's URLs() as list -- HFS format else if fileFormat is POSIX then set theFilePaths to openPanel's filenames() as list -- POSIX format end if return theFilePaths end get_files_folders on report_complete(acount, xfmt) if acount = 0 then quit display dialog "Export is Complete." & return & return & tab & "Export format: " & xfmt & return & tab & "Pages files processed: " & (acount as text) buttons {"Done"} default button {"Done"} with title "Pages Export Facility" with icon POSIX file app_icon as alias return end report_complete on cleanup() tell application "Pages" to if it is running then quit set fileCnt to (0 as integer) set fileList to {} set selected_items to {} return end cleanup on error_handler(nbr, msg) return display alert "[ " & nbr & " ] " & msg as critical giving up after 10 end error_handler

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Batch convert .pages files to .doc /.docx files

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