Previously posted, the v1.5 version of this AppleScript drag & drop application did not support exporting content to a user specified folder. The v2.0 release, posted here today, does offer a query about whether the user wants a separate export folder (default), or just write the exported documents back to their original filesystem location. I have also successfully tested v2.0 with a mounted USB stick.
The v2.0 version will expect OS X Yosemite (10.10) or later, and Pages v5.5.3 or later, though my scope of testing was restricted to El Capitan and Sierra.
In the following, new panel, press return (default) to receive a choose folder prompt, where you can either create a new export folder, or select an existing one. If you change the 'Y' to 'n', and press return, then no export folder will be used.

The list of export formats will be presented as before, with a return key selecting DOCX by default. This script will run 3x faster on El Capitan (Pages v5.6.2) than on Sierra with Pages v6.2. Depending on the quantity of Pages documents dropped on it, this application can take awhile before actual exports begin. The opening, and flashing of Pages for each document is an unavoidable distraction.
Installation, and usage instructions remain as they were for v1.5.
-- pages_export.applescript
--
-- Usage: Drag & Drop Pages document(s), and/or folder(s) containing them.
-- Recursively processes folder contents, and exported files written to specified
-- folder (default), or to original file location with new extension.
-- Export supported and tested: PDF, docx, and doc.
-- Export to USB stick tested successfully.
-- To be saved as AppleScript Application
-- Version: 2.0
-- Tested: OS X El Capitan 10.11.6, macOS Sierra 10.12.5
-- 3x faster on El Capitan with same version of AppleScript
-- Require: OS X 10.10 or later. Pages v5.5.3 or later. Application will check.
-- VikingOSX, 2017-06-30, Apple Support Communities
property ca : current application
property fmsg : "Choose or Create Export Folder:"
property fdefault : (path to desktop) as alias
property export_choices : {"PDF", "DOCX", "DOC"}
property msg : "Choose Pages Export Format:" & return & "DOCX (default - return):"
property exportFormat : ""
property expFolder : ""
property valid_kind : {"Pages Publication", "Pages document"}
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 10.10 or later
use scripting additions
on run
-- only if the user double-clicks the application icon
display alert "Drag and Drop Pages documents and/or folder(s) of Pages documents" & return & ¬
"onto the application icon. Make your export choice from the export type selection."
quit
end run
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
try
set choice to text returned of (display dialog ¬
"Exported files to separate folder (Y/N)?" default answer "Y")
if {"Y", "y"} contains choice then
repeat while true
set expFolder to (choose folder with prompt fmsg default location fdefault ¬
without invisibles, multiple selections allowed and showing package contents)
if not expFolder is equal to fdefault then exit repeat
end repeat
end if
set exportFormat to (choose from list export_choices with prompt msg ¬
default items {"DOCX"} multiple selections allowed false ¬
with empty selection allowed)
if exportFormat is false then error number -128 -- user cancelled
set exportFormat to lowercase (item 1 of exportFormat)
on error errmsg number errnbr
my error_handler("dropped items prep", errnbr, errmsg)
quit
end try
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
set errval to "Dropped Items repeat - " & (anItem as text)
my error_handler(errval, 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
set exportDocument to new_extension(theFile, exportFormat, 0) as POSIX file
if not expFolder = "" then
-- because Finder can't get name of non-existent file at this point
set basename to new_extension(theFile, exportFormat, 1)
set exportDocument to (expFolder & basename) as text
end if
-- necessary to avoid export write permissions issues on Sierra
close access (open for access exportDocument)
on error errmsg number errnbr
my error_handler("Export file exportDocument", errnbr, errmsg)
quit
end try
tell application "Pages"
try
set myDoc to open theFile
with timeout of 1800 seconds
if {"docx", "doc"} contains exportFormat then
export myDoc to file exportDocument as Microsoft Word
else if (version of it) ≥ "5.6" then
export myDoc to file exportDocument as PDF with properties {image quality:Best}
else
export myDoc to file exportDocument as PDF
end if
end timeout
set fileCnt to (fileCnt + 1) as integer
close myDoc saving no
on error errmsg number errnbr
my error_handler("Export file", 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 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 lowercase (astr)
-- make passed string all lowercase
return ((ca's NSString's alloc()'s initWithString:astr)'s lowercaseString()) as text
end lowercase
on error_handler(nbr, msg, handler_name)
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 expFolder to ""
continue quit
end quit