Extract Aliases from second line of text

This Smart Rule script adds aliases from the second line.

Make sure to process each record only once.

-- Smart Rule - Add aliases from second paragraph

on performSmartRule(theRecords)
	tell application id "DNtp"
		try
			repeat with thisRecord in theRecords
				set theText to plain text of thisRecord
				if theText ≠ "" then
					set thisParagraph to paragraph 2 of theText
					set thisParagraph_clean to (characters 1 thru -5 in thisParagraph) as string
					set newAliases_list to my tid(thisParagraph_clean, ", ")
					set oldAliases to aliases of thisRecord
					if oldAliases ≠ "" then
						set oldAliases_list to my tid(oldAliases, {", ", "; ", ",", ";"})
					else
						set oldAliases_list to {}
					end if
					set allAliases to my tid(oldAliases_list & newAliases_list, ", ")
					set aliases of thisRecord to allAliases
				end if
			end repeat
			
		on error error_message number error_number
			if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
			return
		end try
	end tell
end performSmartRule

on tid(theInput, theDelimiter)
	set d to AppleScript's text item delimiters
	set AppleScript's text item delimiters to theDelimiter
	if class of theInput = text then
		set theOutput to text items of theInput
	else if class of theInput = list then
		set theOutput to theInput as text
	end if
	set AppleScript's text item delimiters to d
	return theOutput
end tid