Use MS Word to save documents to plain text

(With thanks to Tim Connor for the extension removal code - found at http://www.objectivelabs.com/scripts.php)

This code is a folder action that will take any Word readable file dropped in a folder and save it as plain text. Known to work for sure in Word 2004 running on OS X 10.4.11. I don’t have any other versions to test with. The commands are general enough that it should work for other versions of Word and OS X. This script requires there to be a folder called “Word to Text” within the folder linked to the action.


on adding folder items to this_folder after receiving added_items
	repeat with i in added_items
		tell application "Microsoft Word"
			activate
			open i without add to recent files
			set fileName to name of active document
		end tell
		try
			set N to count of characters of fileName
			if (N > 3) and character (N - 3) of fileName is "." then
				set fileName to characters 1 thru (N - 4) of fileName
				set fileName to fileName as text
			else
				--there isn't an extension
			end if
		end try
		set fileName to fileName & ".txt"
		set newFolder to "Word to Text:"
		set thePath to (this_folder & newFolder) as string
		set theOutputPath to (thePath & fileName) as string
		tell application "Microsoft Word"
			save as active document file name theOutputPath file format format text
			close active document without saving
		end tell
	end repeat
end adding folder items to

EDIT: I should note that this will have Word try to open ANYTHING you drop in the folder “ pictures, applications, folders, applescripts, etc. If Word doesn’t immediately recognize the file type, it will give you a box to choose which encoding you want to read something as.