Get word and character counts for any selection in OS X

AutomatorIconXIf 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:

  1. Ensure the service receives selected “text” in “any application” using the topmost menus.
  2. Drag the “Run Shell Script” action to the workflow and change the “pass input” option to be “as arguments.”
  3. Copy and paste the following four commands as-is into the Shell script area:
    echo Words:
    echo $1 | wc -w
    echo Characters:
    echo $1 | wc -c
  4. 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.
  5. Drag the “Ask for Confirmation” action to the workflow
  6. 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).
Word Count automator service in OS X

Ensure the workflow looks like this, including changing the Shell script action’s input accordingly (click image for larger view).

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.

8 thoughts on “Get word and character counts for any selection in OS X

  1. Kurt J. Meyer

    Rainmaker’s Spell Catcher seems to install a similar service. It displays the number of words, characters, paragraphs, line feeds, and appendices.

  2. Alan C. Bowen

    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.

  3. nda

    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):

  4. kt

    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!

Comments are closed.