I have been searching high and low for a TextEdit word count script and I found NanoCount that actually does I needed. However, I am used to using the right mouse button to find out the number of words in a text file. (You are right. I was a Windows user.)
Then I discovered Automator which comes with Mac OS X.
TextEdit Word Count: My First Automator Script
I have little programming background and I find the Automator extremely easy to learn. However, I am totally alien to AppleScript and so I decided to google around for similar scripts to use in Automator. Here’s the 2 web pages where I used part of the codes in my TextEdit WordCount script.
Automator Example: TextEdit WordCount Service
First, open Automator in the Applications folder. Select Services.
Click at the option box “any application” to display the pull-down menu. Select Finder
Select Others.
In the Application folder, choose TextEdit.
On the second column of the Automator window, search for the action “Run AppleScript” by entering “run applescript” in the search box.
Double click at “Run AppleScript” or drag and drop this action into the workflow area.
Copy and paste the following codes into the AppleScript widows:
set word_count to count words of (input as string)
display alert "Words: " & word_count
Then, compile the codes by clicking at the hammer icon.
Save the Automator Service.
Next, test out TextEdit Word Count service.
Open a text file using TextEdit, highlight the text which you want to word count. Click the right button on the mouse.
Brilliant, thanks! worked first time. I write all my articles in TextEdit (probably because I’m a geek) and this is something I was missing.
Thanks a lot for this. It was exactly what I needed! It was driving me crazy copying & pasting text out of Notational Velocity just to find out the word count.
Thanks a million!
this is fantastic! I also used this to check word count in Notational Velocity– works like a charm.
thanks for posting.
If you take out the TextEdit aspect you can have it work as a service for any text you select. Super handy.
If you want to keep it all in Automator, you could do something like what I’ve done:
Make a service in automator that receives selected text (in TextEdit or “any application”)
Then add a Run Shell Script step with the command:
wc -w
Then add a Speak Text command in the voice you choose.
Now when you choose the service (I do it with command shift C), it will speak the number of words you’ve typed.
No better or worse than the example really, but a little bit simpler and it works for me.
Brilliant! It was so easy to do, and worked perfectly the first time.
Thank you so much for taking the time to put this together for the rest of us who DON’T have any programming in our backgrounds!
If you modify the script to this:
set word_count to count words of (input as string)
set character_count to count characters of (input as string)
display alert “” & word_count & ” words
” & character_count & ” characters”
… it will print the word as well as the character count (including whitespaces).
To display both Word Count and Character Count, use these codes:
set word_count to count words of (input as string)
set char_count to count characters of (input as string)
display alert "Words: " & word_count & " " & "Characters: " & char_count
Or you can just use the Automator action “Get Length of Text”.