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


Click here to return to the 'Simple word and character count for TextEdit' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Simple word and character count for TextEdit
Authored by: belleboom on May 09, '10 07:33:33PM
Updated code, once I got through fiddling with it. Includes word, character and paragraph counts by document and selection, and a (commented out) option for a voice report instead of a dialog box... because that's awesome:)
tell application "System Events"
	tell process "TextEdit"
		set frontmost to true --> bring app to the foreground
		click menu item 5 of menu 1 of menu bar item 4 of menu bar 1 --> copy selection to clipboard
	end tell
end tell
tell application "TextEdit"
	-- stats for all of document 1
	set word_count to count words of document 1
	set char_count to count characters of document 1
	set para_count to count paragraphs of document 1
	-- stats for selection
	set ch to count characters of (the clipboard)
	set wd to count words of text of (the clipboard)
	set par to count paragraphs of text of (the clipboard)
	-- next two lines announce word totals for selection and document; cool but slows down the dialog display so commented out; use instead of dialog box if you prefer
	--	set alert to "You have " & wd & "words in your selection, and " & word_count & "words in your document"
	--	say alert using "Alex"
	-- open dialog with data, title, icon, close buttonsx2 (same effect for each, can also use Esc for 1 and Enter for 2 to trigger), closes after 20 secs in case you are feeling lazy
	display dialog "Document..." & return & "   Words: " & word_count & return & "   Characters: " & char_count & return & "   Paragraphs: " & para_count & return & return & "Selection..." & return & "   Words: " & wd & return & "   Characters: " & ch & return & "   Paragraphs: " & par buttons {"sob!", "yay!"} default button 2 cancel button 1 with icon 1 with title "Word Count" giving up after 20
end tell
edited for width by crarko
Edited on May 13, '10 05:15:10AM by crarko


[ Reply to This | # ]
Simple word and character count for TextEdit
Authored by: Anonymous on May 10, '10 06:41:08PM

I don't know if you looked at this post after you wrote it, but it could use some line wrapping.



[ Reply to This | # ]
Simple word and character count for TextEdit
Authored by: belleboom on May 11, '10 06:50:20AM

Hmm, right you are and apologies to all, but sadly it seems I can no longer edit the post. How does one insert those useful code boxes in a post?



[ Reply to This | # ]