Inserting Text String only if it Does Not Exist

Hi, I am an AppleScript noob and have been using TextWrangler to edit some xml documents utilizing simple find and replace scripts, select insertion points and line deletion. All are working fine, except I cannot solve the following scenario. What I wish to do in TextWrangler is to use a script which will insert text on a specific line, immediately before an existing word, but only if the text I want to insert does not already exist.

This is what I wish to do;

dab-flags=“NewFormat|PenPicture|SaveRestoreMouseParams”

Which after running the script becomes the string I require;

dab-flags=“NewFormat|PenPicture|SaveRestoreDamping|SaveRestoreMouseParams”

I can use replace “SaveRestoreMouseParams” using “SaveRestoreDamping|SaveRestoreMouseParams” in script format, but if SaveRestoreDamping already exists in the document, the following results;

dab-flags=“NewFormat|PenPicture|SaveRestoreDamping|SaveRestoreDamping|SaveRestoreMouseParams”

So, I would like a way to only perform the replace action if the term SaveRestoreDamping does not already exist in the document, so I can incorporate this into my existing editing scripts. Any ideas? Alternatively, does anyone know of code which would then delete a duplicate occurrence of SaveRestoreDamping| in the document (which would leave one instance).

I forgot to add that the additional xml items such as PenPicture may vary from document to document in both name and number (which is not an issue) and is why I cannot simply replace the whole line, but this line however, must contain SaveRestoreDamping|SaveRestoreMouseParams

tell application "TextWrangler"
	activate
	replace "SaveRestoreMouseParams" using "SaveRestoreDamping|SaveRestoreMouseParams" searching in text 1 of text document 1 options {search mode:literal, starting at top:false, wrap around:false, backwards:false, case sensitive:true, match words:false, extend selection:false}
end tell

David

Sorry to have troubled you all. The answer was so simple I’m now embarrassed :confused:

tell application "TextWrangler"
	activate
	replace "SaveRestoreMouseParams" using "SaveRestoreDamping|SaveRestoreMouseParams" searching in text 1 of text document 1 options {search mode:literal, starting at top:false, wrap around:false, backwards:false, case sensitive:true, match words:false, extend selection:false}
	replace "SaveRestoreDamping|SaveRestoreDamping|SaveRestoreMouseParams" using "SaveRestoreDamping|SaveRestoreMouseParams" searching in text 1 of text document 1 options {search mode:literal, starting at top:false, wrap around:false, backwards:false, case sensitive:true, match words:false, extend selection:false}
end tell