View Character/Word Count For Selected Text From Mac Context Menu

Counting the number of words in a file is probably something you do when you’re in college and you have a paper of a specific length to turn in. There are few other occasions when you would actually need to count the number of characters or words in a file, but if you do, there isn’t a quick way to do so in Mac. A Terminal command does exist that counts characters in a text file, but if you need a more universally applicable solution, you can use this script to create a service that does just  that. You will be able to run it from the context menu, and can forgo having to copy text to the clipboard and then pasting it into an app that does the same.

Open the Automator and select Service when it asks you what you want to create. To create a service, you will need to add an action; in this case, it will be Run AppleScript. Make sure that Text is selected under Service receives selected and Any application is selected in the second dropdown. Paste the following script and save it with any name that will help you remember what the service does.

on run {input, parameters}
		set MyText to input as string
		set NombreSignes to the number of characters of MyText
		set NombreMots to the number of words of MyText
		set NombrePara to the number of paragraphs of MyText
		set LeResultat to "The selected text contains :" & return & "- " & NombreSignes & " sign(s) ;" & return & "- " & NombreMots & " word(s) ;" & return & "- " & NombrePara & " paragraph(s)."
		display dialog LeResultat 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

Go to any app, select text, right-click and choose Services > Name Of Service You Just Created, and small window will appear, giving you the total word, character and paragraph count for the selected text.

The response is a bit slow, but the service works perfectly otherwise. The service will be available in any and all applications that support text.

[via Mac World]

قالب وردپرس

About Kelli Smith

Kelli Smith
Kelli runs customer support and creates content for Skillcrush, a digital skills training and education platform with friendly instructors, an active student community, and laser focus on helping you achieve your career goals with technology. She has an MBA and successfully ran an international company and her own freelancing business before pursuing her passion for tech by taking advanced web development classes. Kelli loves listening to tech podcasts at 2x speed, looking for cute Corgi photos online and teaching and performing country line dancing—as a true Texan living in Finland would do. Say hi on Twitter.

Leave a Reply

Your email address will not be published. Required fields are marked *