I want to use AppleScript to find and replace text in a chosen document. The text I want to replace will always be the same, so I want to set some predefined variables with that string, search the chosen document for that string, and replace it with another predefined string. I want to repeat this find and replace process about 4 times (looking for different string variables each time) for that one document. Once this is done I want to automatically save the modified document.
can someone provide me with simple script to do this? this is that I have so far...
tell application "Finder"
set theFile to (open for access (choose file with prompt "Select a file to read:"))
set txt to (read theFile for (get theFile))
end tell
on replaceText(find, replace, subject)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to find
set subject to text items of subject
set text item delimiters of AppleScript to replace
set subject to "" & subject
set text item delimiters of AppleScript to prevTIDs
return subject
end replaceText
get replaceText("lorem", "ipsum", txt)
the problem is it is not reading all the content of the file (.html). of a lorem ipsum paragraph it is only reading "ipsum ipsum dolor sit amet, consectetur adipisicing elit, sed do eius" i tried using eof in the (get theFile) but that doesnt work either