Applescript find, replace and style
<p>I've been trying to get this simple script to work, it's supposed to search for a string, replace it while applying some styling, e.g. setting the text bold and red. </p>

<p>Here's what I have so far: </p>

<pre><code>tell application "Finder"
    set fl to files of folder POSIX file "/Users/Sc/Desktop/app/" as alias list
end tell
repeat with f in fl
    tell application "TextEdit"

        open f


        set text of front document to replace_chars(text of front document, "a", "0000") of me
    end tell
end repeat

on replace_chars(this_text, search_string, replacement_string)
    set AppleScript's text item delimiters to the search_string
    set the item_list to every text item of this_text
    set the size of replacement_string to 14
    set AppleScript's text item delimiters to the replacement_string

    set this_text to the item_list as string
    set AppleScript's text item delimiters to ""
    return this_text
end replace_chars
</code></pre>

<p>However this produces an error, I understand why, but not sure how to go about styling it before replacement, any help would be appreciated. </p>