script to split RTF files at delimiter

The delimiter is not to blame. 'T was me. Sorry for the rushed job.
This version corrects the problem, and catches errors:```
– Extract multiple text sections
– Place the extracted pieces into a group
– Link the original (unexploded) document to that group
– Adapted by alastor933 from a script by Korm
Explode and group a note (split & title 2)

property delim : “” – enter your delimiter between the quotes

tell application id “com.devon-technologies.thinkpro2”
try
set theDatabase to current database
set theGroup to current group
set theseItems to the selection
if selection is {} then error “Please select some contents”
repeat with thisItem in theseItems
set selectionURL to ((“x-devonthink-item://” & uuid of thisItem) as string)
set targetGroupName to “/Exploded:” & (name of thisItem as string)
set targetGroup to create location targetGroupName in theDatabase
set targetGroupURL to (“x-devonthink-item://” & uuid of targetGroup)
set URL of thisItem to targetGroupURL

		set theText to text of think window 1
		set {TIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, delim}
		set listSections to text items of theText
		set AppleScript's text item delimiters to TIDs
		
		repeat with cSection in listSections
			if length of cSection ≠ 0 then
				set textTitle to paragraph 1 of cSection
				set textContent to paragraphs 2 thru end of cSection
				set {TIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
				set textContent to textContent as text
				set AppleScript's text item delimiters to TIDs
				create record with {name:textTitle, rich text:textContent, type:rtf} in theGroup
			end if
		end repeat
	end repeat
	
on error errMsg number errNum
	if errNum is not -128 then display alert "DEVONthink" message errMsg as warning
end try

end tell