Newbie with a newbie question

Hello

I’m a first time applescript user, and I’ve got a question that will probably sound stupid.
I have a very specific need, and it seems that applescript can make my life easier :

I need to create a very very very long list of names in text-edit, and I’ll be creating it over a period of time. What I need is that once I haven’t entered a name in a while, if I enter a new name that a script checks if it isn’t already in the list.
Basically the script would work like this : I would enter a name in a field, and it would check if this name is already there, and then if it is, it would send a message, if it isn’t, it would add the name to the list.

How can I make this work?

Thanks a lot and sorry if it souns too obvious
Many thanks

Alex

You can take this sample code and adjust it to fit your needs.
This checks every paragraph of the front document opened in TextEdit (every paragraph contains a name) and creates two lists: unique names (namesList) and duplicate names (duplicates):

set namesList to {}
set duplicates to {}
tell application "TextEdit"
	tell document 1
		set paragraphNum to 1
		repeat
			try
				set theParagraph to paragraph paragraphNum
			on error --> no more paragraphs!
				exit repeat
			end try
			
			if theParagraph is in contents of namesList then
				set end of duplicates to theParagraph
			else
				set end of namesList to theParagraph
			end if
			
			set paragraphNum to paragraphNum + 1
		end repeat
	end tell
end tell
{namesList, duplicates}