I have tested this AppleScript on El Capitan 10.11.6 with Pages v5.6.2, and on macOS Sierra 10.12.6 with Pages v6.2, and in both cases, a dropped folder of Pages documents was successfully exported as plain text to the designated Test export folder. When processing is complete, a dialog will appear with the total files processed. Once you click done, the application will then quit.

Once the AppleScript is saved to your Desktop as an application, you only need to drag and drop a file, files, or a folder of any depth containing Pages documents onto the application. It will then interact with you once — allowing you to select an existing folder, or create one, before commencing the export to text process for each file. It is normal for Pages to briefly flash each document to the screen during the individual export process.
Setup.
- From Launchpad : Other : Script Editor.
- Copy/paste the content of the following scrollable AppleScript code into the Script Editor
- Click the hammer icon on the toolbar to compile it. The text will change from purple to colors if there are no errors in the copy process. The code won't run with compile time errors anyway.
- Save the AppleScript code as Applescript (your backup)
File menu : Save...
- Save As: pages_text_export (Documents folder or your preferred location)
- File Format: Text (don't change the Line Endings)
- Hide extension: unchecked (this will allow the .applescript extensin in the Save As window
- Save
- Save the AppleScript code as an Application
Option key + File menu : Save As...
- Save As: any name you want (on your Desktop for drag/drop)
- File Format: Application (leave the options unchecked)
- Hide Extension: Checked (your application name in Save As: will have no extension)
- Save
- Quit the Script Editor
Usage: drag and drop Pages documents or a folder of Pages documents onto the application icon.
Copy this content to the Script Editor per item 2 above:
property ca : current application
property exportFormat : "txt"
property fmsg : "Choose or Create Export Folder"
property fdefault : (path to desktop) as alias
property valid_kind : {"Pages Publication", "Pages document"}
property export_folder : ""
property fileCnt : (0 as integer)
property app_icon : "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/MultipleItemsIcon.icns"
use framework "Foundation"
use AppleScript version "2.4" -- Yosemite or later
use scripting additions
on open dropped_items
tell application "Finder" to set sys_version to version
considering numeric strings
if sys_version < "10.10" then
display alert ¬
"You need OS X Yosemite 10.10 or later to run this script." giving up after 10
quit
end if
end considering
tell application "Pages" to set aversion to version of it
considering numeric strings
if aversion < "5.5.3" then
display alert "You need Pages v5.5.3 or later to run this script" giving up after 10
quit
end if
end considering
set export_folder to (choose folder with prompt fmsg default location fdefault ¬
without invisibles, multiple selections allowed and showing package contents)
repeat with anItem in the dropped_items
try
tell application "Finder"
set akind to kind of anItem
if akind is equal to "Folder" then
set docList to (every item in entire contents of folder anItem whose kind is in valid_kind) as alias list
repeat with afile in docList
my export_file(afile)
end repeat
else if akind is in valid_kind then
my export_file(anItem)
end if
end tell
on error errmsg number errnbr
my error_handler("main - repeat", errnbr, errmsg)
quit
end try
end repeat
display dialog "Export Complete." & return & tab & " Files exported to " & ¬
exportFormat & " : " & (fileCnt as text) ¬
buttons {"Done"} default button "Done" with title "Pages Export Facility" with icon POSIX file app_icon as alias
quit
end open
on export_file(theFile)
try
if not export_folder = "" then
-- construct the new output folder file path with extension
set basename to new_extension(theFile, exportFormat, 1)
set exportDocument to (export_folder & basename) as text
else
-- back to original file path with new extension
set exportDocument to new_extension(theFile, exportFormat, 0) as POSIX file
end if
on error errmsg number errnbr
my error_handler("Export File", errnbr, errmsg)
quit
end try
close access (open for access exportDocument)
tell application "Pages"
try
set myDoc to open theFile
with timeout of 1800 seconds
-- export Pages document as plain text
export myDoc to file exportDocument as unformatted text
end timeout
set fileCnt to (fileCnt + 1) as integer
close myDoc saving no
on error errmsg number errnbr
my error_handler("Export File - Pages", errnbr, errmsg)
quit
end try
end tell
-- force extension visible on all exported documents
try
-- occasionally get -8058 error which is caused by trying to duplicate
-- a mounted drive with the Finder -- which is nonsense here, so ignore.
tell application "Finder"
if exists (item exportDocument as alias) then
set extension hidden of (item exportDocument as alias) to false
end if
end tell
on error errmsg number errnbr
if not errnbr = -8058 then
set errval to "Finder ext hidden: " & exportDocument as text
my error_handler(errval, errnbr, errmsg)
quit
end if
end try
return
end export_file
on new_extension(afile, ext, name_flag)
-- handler has two roles based on name_flag value
-- 0) return full path of original filename with replacement extension
-- 1) return just the basename with new extension, but without path
set fullPath to ca's NSString's alloc()'s initWithString:(POSIX path of afile)
set newfile to (fullPath's stringByDeletingPathExtension)'s stringByAppendingPathExtension:ext
if name_flag = 1 then
return (newfile's lastPathComponent()) as text
end if
return newfile as text
end new_extension
on error_handler(handler_name, nbr, msg)
return display alert handler_name & ": " & "[ " & nbr & " ] " & msg as critical giving up after 10
end error_handler
on quit {}
-- perform these cleanup items, and then really quit
tell application "Pages" to if it is running then quit
set fileCnt to (0 as integer)
set exportFormat to ""
set export_folder to ""
continue quit
end quit