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

In this article, we're going to show you how to create a system-wide service that enables you to get an immediate word count and character count in TextEdit, Safari, Mail, or indeed any app on your Mac that lets you highlight text. It offers a handy home-made solution if you often find yourself pasting into a blank Word or Pages document for no other reason than to find out how many words are in a text selection.


The steps below will guide you through the process of creating your own word count service using the macOS Automator app. It's a simple procedure to follow and should only take five minutes, but if you'd rather use a third-party solution, then check out WordCounter, a free Mac menu bar utility from Onekerato.

How to Create a Word Count Service in Automator


  1. Launch Automator from the Applications folder.

  2. Click New Document.
  3. Choose Service as the type of your document.

  4. Type "run" into the Library search field at the top of the Automator sidebar, then drag the Run Shell Script action into the empty workflow area.

  5. In the Run Shell Script action window, change the Pass Input: option to as arguments using the dropdown menu.

  6. Clear the text in the shell script box (highlight the text with your mouse cursor and hit Backspace) then copy and paste the following text into the same area:


    echo Words:

    echo $1 | wc -w

    echo Characters including spaces:

    echo $1 | wc -c

  7. Clear the Library search field at the top of the Automator sidebar and type "set value", then drag the Set Value of Variable action into the workflow area.

  8. Click the Variable: dropdown menu and select New Variable....
  9. In the blue dialog that appears, click inside the Name: input field. It may default to "storage", but you can rename it – we'll call it "count". Click Done, and you should now see "count" (or whichever name you used) appear in the variable list below the workflow area.

  10. Clear the Library search field at the top of the Automator sidebar again, and this time type "ask", then drag the Ask for Confirmation action into the workflow area.

  11. Now, drag your "count" variable from the variable list up to the "Message" title in the Ask for Confirmation action.

  12. In the Automator menu bar, select File -> Save..., call your new service "Word Count", and click Save.
Next time you want to get a word count and/or character count for some text you've highlighted, simply right-click (or Ctrl-click) on the text and select Services -> Word Count from the contextual dropdown menu.


You can assign a key shortcut to it for even faster access. To do so, launch System Preferences, select the Keyboard pane, and click the Shortcuts tab. Select Services from the sidebar and you should find Word Count near the bottom of the list. Just click it, select Add Shortcut, and finally, enter your custom key combination.



Related Roundup: macOS High Sierra


Top Rated Comments

(View all)
Avatar
19 weeks ago
Srsly guys... I don't think I'll need this. But you rock! Keep these guides and tutorials coming!!! They are MUCH appreciated!
Rating: 10 Votes
Avatar
19 weeks ago

Srsly guys... I don't think I'll need this. But you rock! Keep these guides and tutorials coming!!! They are MUCH appreciated!

Was gonna say exactly this till I saw your post. Reminds me of MacOXSHints.
[doublepost=1526030048][/doublepost]

Or get WordService for free from the App Store to give you text stats and so much more:
https://itunes.apple.com/app/wordservice/id899972312?mt=12

Maybe but this also teaches you stuff.
Rating: 5 Votes
Avatar
19 weeks ago
Or get WordService for free from the App Store to give you text stats and so much more:
https://itunes.apple.com/app/wordservice/id899972312?mt=12
Rating: 2 Votes
Avatar
19 weeks ago
Automator is one of the many amazing productivity features in macOS that few know about. It's saved me so much time.
Rating: 2 Votes
Avatar
19 weeks ago

Interesting. Writing a service like this seems like it might be easier than writing a Sublime plugin which is what I normally do when I want to automate a common text related activity.

Although sublime plugins are cross platform whereas services would only work on a Mac.

There are definitely existing Sublime plugins for word count. I'm using this one ('https://github.com/titoBouzout/WordCount')and it's great.



Rating: 1 Votes
Avatar
18 weeks ago

There are definitely existing Sublime plugins for word count. I'm using this one ('https://github.com/titoBouzout/WordCount')and it's great.


Of course. There's plenty of plugins for Sublime for anything lots of people need to do.

I was saying that, more generally, I write plugins for Sublime when I regularly need to do something with text in some specific way. As opposed to writing a MacOS service, where it'll only work on Macs.
Rating: 1 Votes
Avatar
19 weeks ago

Or get WordService for free from the App Store to give you text stats and so much more:
https://itunes.apple.com/app/wordservice/id899972312?mt=12


Beat me to it. I've used this indispensable collection of services for over 15 years. Can also be downloaded here:

https://www.macupdate.com/app/mac/10523/wordservice
[doublepost=1526061714][/doublepost]

Maybe but this also teaches you stuff.


I learned that I don't have to do it myself. ;)
Rating: 1 Votes
Avatar
19 weeks ago

Srsly guys... I don't think I'll need this. But you rock! Keep these guides and tutorials coming!!! They are MUCH appreciated!


absolutely !! very useful read
Rating: 1 Votes
[ Read All Comments ]