Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sammich

macrumors 601
Original poster
So i've been doing some cleaning up of some old documents, all done in rtf in TextEdit. But now I have some hundreds of related files and I want to compile them all into a single rtf document (ie: preserving all formatting).

I googled this and it came up with this:

from http://forums.macosxhints.com/showthread.php?t=77966
Code:
tell application "Microsoft Word"
	set the_folder to choose folder "Choose your folder of RTF files"
	set the_files to (my get_folder_list(the_folder, "rtf"))
	set combineDoc to make new document
	repeat with rtffile in the_files
		open rtffile
		set curDoc to the active document
		select the text object of curDoc
		copy object selection
		close curDoc saving no
		collapse range text object of combineDoc direction collapse end
		paste object selection
	end repeat
end tell

on get_folder_list(the_folder, file_extension)
	set the_files to {}
	tell application "Finder" to set folder_list to every file of folder the_folder whose name ends with file_extension
	repeat with new_file in folder_list
		copy (new_file as string) to end of the_files
	end repeat
	return the_files
end get_folder_list

This script does almost everything I need (except MS Word is seriously slow), but could anyone modify it so that it also includes the filename in the compilation? I've been trying everything and I can't get it to work. Also, what order are the files read into the list? Can it done so that it is ordered by name?

Can some AppleScript gurus help me here? I've tried but I have no idea how to include the filename?
Thanks in advance!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.