alnyden;
I guess the best advice is to walk before trying to run. There are many ways to do what you’re asking for, but the first step is to deal with a single document and do your search and replace in it. Unless your documents are extremely large, the easiest way to do this, while gaining some understanding of what’s going on, is to read each each file into your script as a variable, do the search and replace in the script and write it back to the file replacing what was there or into a new file if you want to keep the old.
TextEdit will work, but in my view, if you must use an application, use TextWrangler which is free and has an excellent search and replace.
In plain vanilla AppleScript, the content of a text file is grabbed this way:
tell application "Finder" to set theFile to selection as alias
set f to (open for access theFile with write permission)
set theText to read f
close access f
theText
To search and replace something in that file this handler by Jon Nathan is as effective as any:
on snr(the_string, search_string, replace_string)
tell (a reference to my text item delimiters)
set {old_tid, contents} to {contents, search_string}
set {the_string, contents} to {the_string's text items, replace_string}
set {the_string, contents} to {the_string as Unicode text, old_tid}
end tell
return the_string
end snr
Finally, if you really do want to use TextEdit for this, then this will do it for one document and you can expand it to many:
tell application "TextEdit"
activate
choose file
open result
set theDoc to text of document 1
searchReplace of me into theDoc at "TextToFind" given replaceString:"TextToSubstitute"
set text of document 1 to result
end tell
on searchReplace into mainString at searchString given replaceString:replaceString
repeat while mainString contains searchString
set foundOffset to offset of searchString in mainString
set stringStart to text 1 through (foundOffset - 1) of mainString
set stringEnd to text (foundOffset + (count of searchString)) through -1 of mainString
set mainString to stringStart & replaceString & stringEnd
end repeat
return mainString
end searchReplace