Ok, I cracked it. The next phase was to make a personal letter to each of three persons of a list in 3 separate files with filenames containing the name of the corresponding person instead of both "Personal" (i.e., "Stan letter.rtf", "Ben letter.rtf" etc) and the placeholder "NAME_PLACEHOLDER" (so as to create "Dear Stan" line). The code is below. I get only the filename part working but not the "NAME_PLACEHOLDER" part. What's wrong?
I'm posting the entire code consisting of the TextEdit doc and individualized personal letters creation steps I used.
set doc_extension to "rtf"
set my_sign to "Kindest regards" & return & "My_initials"
set doc_contents to "Dear NAME_PLACEHOLDER" & return & return & "You're invited to join us in the office on Monday for pizza" & return & my_sign
set doc_name to (path to desktop as text) & "Personal letter" & "." & doc_extension
tell application "TextEdit"
activate
tell application "Finder"
if file doc_name exists then
delete file doc_name
end if
end tell
set new_doc to make new document with properties {text:doc_contents, name:doc_name}
tell text of new_doc
if doc_extension is "rtf" then
set font to "MyriadPro-Regular"
set size to 18
end if
end tell
close new_doc saving in file doc_name saving yes
tell application "Finder" to set extension hidden of file doc_name to false
end tell
set names_list to {"Ben", "Jen", "Sten"}
set desktop_path to ((path to desktop) as text)
repeat with name_ref in names_list
tell application "Finder"
if file ((desktop_path & name_ref & " letter." & doc_extension)) exists then
delete file (desktop_path & name_ref & " letter." & doc_extension)
end if
end tell
tell application "TextEdit"
open (desktop_path & "Personal letter." & doc_extension) as alias
tell document 1
set (every word where it is "NAME_PLACEHOLDER") to contents of name_ref
save in file (desktop_path & name_ref & " letter." & doc_extension)
close saving yes
end tell
end tell
end repeat