Automator Replace text inside a text file
I have absolutely no idea about coding, for a couple weeks I was playing around with automator, Mac OS... but I'm stuck when I attempt to create an automation to ask for a text and then based on the answer I could replace a couple of "variables" inside a text file and then just simply save this text file...
I've tried to play around with this code, but all the time an error in apple script:
set stringToFind to "replace that"
set stringToReplace to "with this"
set theFile to choose file
set theContent to read theFile as «class utf8»
set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, stringToFind}
set ti to every text item of theContent
set AppleScript's text item delimiters to stringToReplace
set newContent to ti as string
set AppleScript's text item delimiters to oldTID
try
set fd to open for access theFile with write permission
set eof of fd to 0
write newContent to fd as «class utf8»
close access fd
on error
close access theFile
end try
Any ideas how to master it? Or where to look for the answer? I spend several hours trying to solve it but without any progress... Thank you in advance