Keeping order

I’ve lost track of a script’s variables often enough.
So I wrote this simple script to list them into my “PIM”, Mori.

I’d like to hear about your solutions - and improvements that you can think of.

-- Use:	to find synonyms
--		to create a reference database
--		to streamline variable naming
--
-- to find vars in a script:
-- 	paste compiled script into TextEdit RTF
-- 	delete code from beginning up to first var
-- 	then run this script
--
--	script will create entries in Mori
--	which are titled with the variable name
--      entry's note can be used to add info
--
tell application "TextEdit"
	set varColor to color of word 1 of front document --> sample: {8481, 0, 60909}
	set varList to words of front document where it's color is varColor -- 'whose' does not work
end tell
-- remove duplicates
set varList to removeDuplicates(varList)
-- don't sort! they are in script's order

-- create Mori entries
-- target notebook must be open
tell front document of application "Mori"
	repeat with anItem in varList
		make new entry at end of entry named "Inbox" with properties {name:anItem}
	end repeat
end tell


on removeDuplicates(theList)
	-- <http://macscripter.net/viewtopic.php?id=11360>
	-- theList can contain any type of item
	set returnList to {}
	repeat with anItem in theList
		if returnList does not contain anItem then set end of returnList to (contents of anItem)
	end repeat
	return returnList
end removeDuplicates

Model: iMac G5
Operating System: Mac OS X (10.4)