Add a word-count tool to TextEdit

TextEdit is a nice, lightweight text editor, but in at least one sense it’s too lightweight: It doesn’t have a word-count feature. MacOSXHints.com reader mprussel figured out a solution: An Applescript that “adds a word (and character) count pop-up dialog” to OS X’s built-in editor:

tell application "TextEdit"
  set word_count to count words of document 1
  set char_count to count characters of document 1
  set show_words to (word_count as string) & " words. (" & (char_count as string) & " characters.)"
  set dialog_title to "TextEdit Word Count"
  display dialog show_words with icon 1 with title dialog_title buttons {"Ok"} default button "Ok"
end tell

Copy and paste the above into AppleScript Editor (in Applications/Utilities), and save it in your user directory's Library/Scripts/Applications/TextEdit folder; I named mine Word Count. Next, open AppleScript Editor’s Preferences, and on the General tab, make sure Show Script Menu in Menu Bar is selected.

Now, with any TextEdit document in front of you, you can open the Script menu in the menu bar and select your script. When you do, you should see a small dialog saying something like:

TextEdit Word Count
2832 words. (15060 characters.)

The OK button dismisses the dialog box.

As the Hints commenters point out, there are some other ways to do much the same thing. Reader kirsch provided a link to a post on Daring Fireball that explained how to create a system-wide word-count service (again, based on an AppleScript). You could also embed the same kind of script in an Automator-based service, which would then be available in any app. And reader Stormchild pointed out that Devon Technologies offers the free WordService; its Statistics tool provides word and character counts.

Subscribe to the MacWeek Newsletter

Comments