public
Last active

Word and Character Count service for Mac OS X

  • Download Gist
Word and Character Count.scpt
AppleScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# Word and Character Count service for Mac OS X
 
# Adds a Word and Character Count option to the text selection context menu
 
# Use Automator.app to create a new service, and then select the Run AppleScript
# action. Paste in this code and save as Word and Character Count. Now switch to
# a new app, select some text, and open the context menu to find the new option.
 
# Copyright 2012, Noah Slater <nslater@apache.org>
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice and this
# notice are preserved. This file is offered as-is, without any warranty.
 
on run {input, parameters}
tell application "System Events"
set _appname to name of first process whose frontmost is true
end tell
set word_count to count words of (input as string)
set character_count to count characters of (input as string)
tell application _appname
display alert "" & word_count & " words, " & character_count & " characters"
end tell
return input
end run

This is so great. I've needed this and was going to write myself a Chrome add-on, but I realized I needed it in the Creative Suite, as well. Thanks!

Thank you this is very helpful! After this I went to Services Preferences and made a new shortcut for this which simplifies it just that little bit more

That worked beautifully. Thanks for sharing.

Very useful bit of script, saves me having to copy and paste text into an editor every time I need to write a constrained amount in an email or web form. Thanks a lot!

Running 10.6. When I run it in Automator, I get the word and character count, but in any other app I get an error: "The action “Run AppleScript” encountered an error."

@scienceandpoetry hmm, that's strange. It works for me. If you have a patch, let me know, and I'll update the code. Or if have steps to reproduce, share them, and I'll try to patch myself.

Thanks for this, Noah! Very helpful.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.