Splitting Files with a twist?

I am trying to do some fairly simple text manipulation but I’m having a bit of trouble.

I have followed this http://www.devon-technologies.com/phpBB2/viewtopic.php?t=3479&start=0&postdays=0&postorder=asc&highlight=name
and gotten the basic script to work but what I want to do is modify how the new files are named.

Ideally as the script runs it will pull the first word from each section of text and use that as the new name. For some reason I cannot get that to work at all. Here is what I have so far:

tell application "DEVONthink Pro"
	set theSelection to the selection
	set SplitPointRegEx to "#"
	set OldDelimiters to AppleScript's text item delimiters
	repeat with CurrentItem in theSelection
		set AppleScript's text item delimiters to SplitPointRegEx
		set theSource to the plain text of CurrentItem
		set RepeatCount to 0 as integer
		set TotalCount to (count each text item of theSource) as integer
		
		repeat until RepeatCount is equal to TotalCount
			set RepeatCount to RepeatCount + 1
			set CurrentText to (text item RepeatCount of theSource)
			set Title to (word 1 of CurrentText)
			if length of CurrentText is greater than 0 then
				create record with {name:Title, type:txt, plain text:CurrentText}
			end if
		end repeat
	end repeat
	
	set AppleScript's text item delimiters to OldDelimiters
end tell

I can tell that the line ```

set Title to (word 1 of CurrentText)


set Title to (text item 1 of CurrentText)


it produces the same file names as the original script in the thread linked to above.  However, that's not what I want.  I've used a few variations such as 

set Title to (word item 1 of CurrentText)


but without luck.  Any ideas?  

Thanks,

Sasha

Words and paragraphs are only supported while scripting the visible rich text of a window (e.g. “text of think window 1” or “selected text of think window 1”). To split a string into words you have to use text item delimiters, for example a space.

Something like


set theOldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set theWords to the text items of CurrentText
set Title to text item 1 of theWords
set AppleScript's text item delimiters to theOldDelimiters

Hope that works. Note: I wrote that script a long time ago, and I’ve learned a lot since then. There is probably a better way to do the rest of the script, but I’m busy now and can’t contemplate it too deeply.