I am trying to create an applescript
that will search for certain texts in a text file that are unfortunately variable (so every file I am supplied could have for instance of a different languages as the text that need finding GERMAN, FRENCH etc).
Then I need to replace this text with a user defined value. The text surrounding this is however a constant so,
For example the text file will contain order="GERMAN"
where GERMAN needs to be replace by the users text.
I have written the code below where stringtofind
is defined as GERMAN but what I really need is to define stringtofind
as the value of whatever text appears between order=" and "
.
The other issue, I have after this is that the file can in theory contain multiples of this value along with another value (so for instance a file could contain instances of order="GERMAN"
along with instances of order="FRENCH"
. In these cases I need that, user should be able to define different values for these (so all instance of GERMAN can be set to one replacement value and all instances of FRENCH can be set to a different value by the user)
Any assistance with this would be greatly appreciated.
tell application "System Events"
activate
set myFile to choose file with prompt ("Select a file to be processed")
end tell
set stringtofind to "GERMAN"
display dialog "Please enter a value for " & stringtofind default answer "1"
set x to text returned of the result as string
tell application "TextEdit"
open myFile
-- Find and replace
set every word of front document where it = stringtofind to x
end tell