The following AppleScript will use Pages '09 to convert Rich Text (RTF) and Rich Text Documents with Attachments (RTFD) files to Word .doc format. It is strictly a drag and drop application, where you can drop singular file(s)/folder(s), or mixtures of file(s)/folder(s) on it. Output MS Word .doc files will be written back to the location of the original rtf/rtfd document. There may be some content in RTF/RTFD documents that Pages cannot manage.
The AppleScript has been tested on Mavericks (10.9.5), and Yosemite (10.10.5), but not El Capitan (as of this post). It assumes that Pages '09 is located in your Applications/iWork '09 folder, which would be the case if an iWork '09 DVD install, or the installation of Pages v5 over a prior App Store purchase of Pages '09.
You do not need to know AppleScript in order to make this code into an application. It is a tested black box. You know, the kind where you put a nickel in it and a hand comes out to switch it off. You will be saving the script source, and then the Desktop application.
Installation Instructions
- Click on the Launchpad icon in your Dock. Click on the Other folder.
- For Mavericks, click once on AppleScript Editor
- For Yosemite, click once on Script Editor
- Copy and paste the AppleScript code below (not the word AppleScript Source) into either of these editors
- On the editor's toolbar, click the compile (hammer) icon. A successful compile begets multi-colored text.
- From the editor's File menu, choose Save… and from the save panel:
- Save As: rtf2doc
- Click in the Favorites sidebar — Documents
- File Format: Text (rtf2doc will now change to rtf2doc.applescript — a text file)
- Hide Extension is unchecked
- All other defaults remain unchanged
- Save
- From the editor's File menu, press the option key and choose Save As…
- Save As: rtf2doc
- Click in the Favorites sidebar — Desktop
- File Format: Application
- Hide Extension is checked
- Options: all unchecked
- Save
- Quit your AppleScript Editor
You now have a functional application on your desktop.
AppleScript Source
(*
Name: rtf2doc.applescript
Usage: Drag/drop Desktop conversion application
Input: Individual File(s) and/or folder(s) of RTF/RTFD documents
Output: Word .doc file written to input file location
Assume: Pages '09 is located in Applications/iWork '09 folder
Tested: OS X 10.9.5, OS X 10.10.5
Author: VikingOSX, Apple Support Community, Oct. 2015
Rev: 1.0
*)
use scripting additions
property allowed_extensions : {"rtf", "rtfd"}
property Pages09 : ((path to applications folder) as text) & "iWork '09:" & "Pages.app:"
-- drop target for files and folders
on open of fileObjects
set code_block to "Main" -- for error handler
try
repeat with aFile in fileObjects
tell application "Finder" to set itemProp to properties of aFile as list
-- strictly a folder here
if (item 1 of itemProp) contains «class cfol» then
tell application "Finder"
-- drill down into entire dropped folder hierarchy
set rtf_list to (every item in the entire contents of folder aFile whose name extension is in allowed_extensions) as alias list
end tell
repeat with anItem in rtf_list
process_rtf(anItem)
end repeat
-- restrict to rtf/rtfd name extensions
else if (item 5 of itemProp) is in allowed_extensions then
process_rtf(aFile as alias)
end if
end repeat
on error errmsg number errnbr
err_handler(code_block, errnbr, errmsg)
quit
end try
tell my application "Pages" to if it is running then quit
return
end open
on process_rtf(theFile)
set code_block to "process_rtf"
try
-- trim extension from filename
tell application "Finder"
if (length of ((name extension of theFile) as text) as integer) = 4 then
set wordDoc to text 1 thru -6 of (theFile as text) -- remove rtfd
else
set wordDoc to text 1 thru -4 of (theFile as text) -- remove rtf
end if
end tell
-- add new extension for output file
set wordDoc to wordDoc & "doc"
tell my application Pages09
open theFile
save front document as "Microsoft Word 97 - 2004 document" in wordDoc
close front document saving no
end tell
on error errmsg number errnbr
err_handler(code_block, errnbr, errmsg)
quit
end try
return
end process_rtf
on err_handler(location, nbr, msg)
-- dialog will self-destruct in 15 seconds
display alert "RTF to Word Application Error" message "Location: " & location & return & "[" & nbr & "]: " & msg ¬
as critical giving up after 15
tell my application Pages09 to if it is running then quit
return
end err_handler