Previous  |  Main  |  Next
AppleScript Logo

Count Characters of Selected Text

Script for: Mailsmith 1.x, 2.x (OS 9 & OS X)
Copyright: Free, use at your own risk!
Description: Counts the characters selected in a Mailsmith document.
Necessary: None
Download: Count_Chars.hqx
History: v1.1  -  supports Mailsmith 2.x under OS X
v1.0  -  initial version released on this site
The Script:
tell application "Mailsmith"
	try
		set f to selection
		if (class of f is not in {string, character}) or (f = "") or (f = {}) then set f to 0 -- selected mailbox/message or no selected text or mailbox/message  ->  0
		if f is not 0 then -- let's only work on strings
			set g to count of (f as string)
			if g = 1 then
				set Plural to ""
			else
				set Plural to "s"
			end if
			if g < 73 then -- just some fun!
				set theButton to "OK"
			else
				set theButton to "That's much!"
			end if
			display dialog "The selection contains " & (g as string) & ¬
				" character" & Plural & "." buttons {theButton} default button 1 with icon note
		else
			my SelectInfo()
		end if
	on error Errtxt number ErrNo
		beep
		if ErrNo is not -1700 then
			display dialog "The following error has occurred:" & return & return & ¬
				Errtxt & return & "(Error No: " & ErrNo & ")" buttons {"Oops!"} default button 1 with icon caution
		else
			my SelectInfo()
		end if
	end try
end tell


on SelectInfo()
	display dialog "You have to select some text in order to " & ¬
		"use this script!" buttons {"OK"} default button 1 with icon caution
end SelectInfo

 


Contact: Matthias Steffens  |  Previous  |  Main  |  Next  |  Last Updated: 15-Jul-03