Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Build a service to count characters, words and paragraphs' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Build a service to count characters, words and paragraphs
Authored by: newscientist on May 01, '12 09:49:34AM
Here's the script without the French with added checks for single words, characters, etc.

on run {input, parameters}
	try
		set MyText to input as string
		set numChars to the number of characters of MyText
		set numWords to the number of words of MyText
		set numPara to the number of paragraphs of MyText
		set theResult to "The selected text contains:" & return & "- "
		
		if numChars is 1 then
			set theResult to theResult & numChars & " character;" & return & "- "
		else
			set theResult to theResult & numChars & " characters;" & return & "- "
		end if
		
		if numWords is 1 then
			set theResult to theResult & numWords & " word;" & return & "- "
		else
			set theResult to theResult & numWords & " words;" & return & "- "
		end if
		
		if numPara is 1 then
			set theResult to theResult & numPara & " paragraph."
		else
			set theResult to theResult & numPara & " paragraphs."
		end if
		
		display dialog theResult buttons {"OK"} default button 1 with icon note
	on error errmsg number errnum
		display dialog errmsg & " [" & errnum & "]" buttons {"OK"} default button 1 with icon stop
	end try
	return input
end run


[ Reply to This | # ]