Universal Word Count

Sometimes when we write we need to know how many words or characters we are writing. There might be word limits on an assignment submission or we just want to control the size of what is being written. Some software have a word count tool. Some software doesn’t. This universal word count can be used in TextEdit and Notes or anywhere that text can be selected.

We use Automator to create a service that will count words and characters in selected text. Follow the instructions below.

1. Launch Automator

Go to the applications folder and launch Automator.

Alternatively use Spotlight Search by pressing command-space and typing “auto” then Return.

2. Create a New Automator Document

A new document may be created automatically. If not press command-N.

3. Select Quick Action

A Quick Action becomes a service. Services are useful because they can be easily access through a right click or can have a keyboard shortcut attached to them.

Select Quick Action as the document type.

4. Run Shell Script Action

The shell script will do the work of counting the words and characters for us. We need to select the Run Shell Script action.

Do this by typing “run” in the search field. It can also be found under the Utilities category.

Drag the Run Shell Script action to the grey area on the right column.

The Run Shell Script action will appear.

5. Change Pass Input

Change the Pass input by clicking the dropdown and selecting “as arguments”.

Some code appears and we will change that.

6. Copy and Paste Word Count Script

Copy the following script…

echo Words:
echo $1 | wc -w
echo Characters including spaces:
echo $1 | wc -c

Select the old script and paste the new script in its place.

The echo command writes any specified operands, separated by single blank characters and followed by a newline character.

The wc command displays the number of words (-w), and characters (-c) contained in the argument.

This is the simplest way to do it. AppleScript can do this too but is more complex.

7. Put the Result into a Variable

Drag a new action to the workflow called Set Value of Variable.

Search for “set val” or look for it under the Utilities category.

8. Create New Variable

Select the Variable drop down menu and choose New Variable.

Change the name from Storage to Count.

9. Display the Result

Drag the Ask for Confirmation action to the grey area.

Search for “ask” or look under Utilities.

Drag count variable from the footer to the Message field.

10. Copy to Clipboard (Optional)

I like to paste my word count for later reference so I have added the Copy to Clipboard action at the end.

Search for “copy” or look under Utilities.

This copies the results to the clipboard so it can be pasted.

11. Save Your Quick Action as Word Count

Select File > Save and save it under the name Word Count.

It will save it directly into the ~/Library/Services folder ready to go.

12. Test it Out (Right Click)

Open a note or text file and select some text.

Right click on the selected text and select Services > Word Count (find it at the bottom).

Vua la!

13. Attach a Keyboard Shortcut

To make the word count action quicker we can attach a keyboard short cut.

  1. Open Keyboard System Preferences
  2. Select the Shortcuts tab
  3. Select the Services category
  4. Scroll down to Word Count which is near the bottom under the Text category
  5. Select it and press Return so that the shorcut can be created
  6. Make the shortcut unique. Shift-Option-Command-W worked for me

14. Test it Out (Keyboard Shortcut)

Open a note or text file and select some text.

Press Shift-Option-Command-W or your shortcut.

It works!

Here is the complete Automator action…

Thank to MacRumors for How to Set Up a System-Wide Word Count Service on Your Mac

Leave a Reply