If you regularly need to count the words in text that you are composing or otherwise managing, then there are several approaches for doing this. A common one is to simply copy whatever text you are interested in and paste it in a Word or Pages document, and then use the word counting features in there to count your words; however, if you find yourself doing this frequently then you can create a special service for counting words.
To do this, open Automator on your Mac and create a new Service workflow, then perform the following steps to set it up:
- Ensure the service receives selected “text” in “any application” using the topmost menus.
- Drag the “Run Shell Script” action to the workflow and change the “pass input” option to be “as arguments.”
echo Words: echo $1 | wc -w echo Characters: echo $1 | wc -c
- Drag the “Set Value of Variable” action to the workflow and choose “New Variable” from its drop-down menu. Give this variable some unique name like “returnedText.” You should see this variable appear in the variable list below the workflow.
- Drag the “Ask for Confirmation” action to the workflow
- Drag the “returnedText” variable from the variable list to the confirmation action’s title area (you might not be able to drag it to the message area).
When finished, save the workflow with a name like “Word Count” and you should be good to go. Now simply select text in any application, and then right-click it and choose the Word Count service from the contextual menu (it may be in a “Services” submenu) and you will see a message pop up with the number of words and characters in your selection.
In addition to accessing this from the Services menu, you can go to the Keyboard Shortcuts section of the Keyboard system preferences, and locate the new service in the “Services” category. Then select it and click the “Add Shortcut” button to give it a unique hotkey of your choosing. I recommend using something like Shift-Control-Option-W, or another hotkey with more than two modifiers in it, to ensure it is unique.
Rainmaker’s Spell Catcher seems to install a similar service. It displays the number of words, characters, paragraphs, line feeds, and appendices.
This works as it should except for text selected in my .pdf files that have been opened with Acrobat Pro 11.0.07. No problem using Preview.
Thank you Topher. Your script works like magic. You’re the man. (:-)
An easy and effective alternative is using DEVON Technolgies’ free WordService, available since the olden days of [Mac] OS X 10.4 (there’s still a legacy version): http://www.devontechnologies.com/download/products.html
Great tip, thanks.
This doesn’t seem to work with the newest versions of Safari. What do I need to do to make it work now?
Never mind! It does work. I’ve never done anything like this before and chose “work flow” instead of “services work flow” in the very first step. Thank you! You’ve totally made my day!