Automator weirdness

I am trying set up a text service that will break up the input into a set of sentences. This handle breaks things up like I want:


on extractSentences(parameter)
	local domainList, currentDelim, textItemCount, theTextItem, theFirstThreeLetters, newItem
	set domainList to {"com", "net", "org"}
	set currentDelim to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "."
	set parameter to text items of parameter
	set AppleScript's text item delimiters to currentDelim
	set textItemCount to the count of parameter
	repeat while textItemCount > 1
		set theTextItem to item textItemCount of parameter
		if the length of theTextItem ≥ 3 then
			-- this is so blah.com and other selected domains don't cause a sentence break
			set theFirstThreeLetters to text 1 thru 3 of theTextItem
			if the theFirstThreeLetters is in domainList then
				set newItem to item (textItemCount - 1) of parameter & "." & theTextItem
				set item (textItemCount - 1) of parameter to newItem
				set parameter to items 1 thru (textItemCount - 1) of parameter & items (textItemCount + 1) thru -1 of parameter
				set textItemCount to textItemCount - 1
			end if
		end if
		set textItemCount to textItemCount - 1
		
	end repeat
	return parameter
end extractSentences

when I do a Run Applescript in Automator,



on run {input, parameters}
	set sentenceList to extractSentences(parameters)
	--note: i'm not worried about returning the results, I'll work on stuff here. excluded for brevity.
	return input
end run

on extractSentences(parameter)
	local currentDelim, textItemCount, theTextItem, theFirstThreeLetters, newItem, domainList
	set domainList to {"com", "net", "org"}
	set currentDelim to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "."
	set parameter to text items of parameter
	set AppleScript's text item delimiters to currentDelim
	set textItemCount to the count of parameter
	repeat while textItemCount > 1
		set theTextItem to item textItemCount of parameter
		if the length of theTextItem ≥ 3 then
			set theFirstThreeLetters to text 1 thru 3 of theTextItem
			if the theFirstThreeLetters is in domainList then
				set newItem to item (textItemCount - 1) of parameter & "." & theTextItem
				set item (textItemCount - 1) of parameter to newItem
				set parameter to items 1 thru (textItemCount - 1) of parameter & items (textItemCount + 1) thru -1 of parameter
				set textItemCount to textItemCount - 1
			end if
		end if
		set textItemCount to textItemCount - 1
		
	end repeat
	return parameter
end extractSentences

I get a syntax error, “Can’t get every text item.” on the line “set parameter to text items of parameter”
changing the line to something like “set blah to text items of parameter” doesn’t fix the problem.

anyone see why that would happen?

Hi,

as the plural implies, parameters are multiple items aka a list.
Even if you pass only one item you have to dereference the list, e.g.

on extractSentences(theItems)
if count theItems = 0 then return
set parameter to item 1 of theItems
.

Thanks,

that did the trick.