Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Word and Character Count service for Mac OS X
-- Word and Character Count service for Mac OS X
-- Adds a Word and Character Count option to the text selection context menu
-- Use Automator to create a new service, then select the Run AppleScript action. Make
-- sure the service is set to receive "text", at the top of the window. Paste in this code
-- and save as "Word and Character Count". Now switch to a new app, select some text,
-- right-click, go to Services, and find the new option.
-- Copyright 2015, 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
@thenickcox

This comment has been minimized.

Show comment Hide comment
@thenickcox

thenickcox Apr 5, 2012

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!

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!

@nslater

This comment has been minimized.

Show comment Hide comment
@nslater

nslater Apr 5, 2012

You're welcome!

Owner

nslater commented Apr 5, 2012

You're welcome!

@wmp3

This comment has been minimized.

Show comment Hide comment
@wmp3

wmp3 Oct 12, 2012

awesome thanks

wmp3 commented Oct 12, 2012

awesome thanks

@horatiodyball

This comment has been minimized.

Show comment Hide comment
@horatiodyball

horatiodyball Feb 19, 2013

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

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

@soto97

This comment has been minimized.

Show comment Hide comment
@soto97

soto97 May 31, 2013

That worked beautifully. Thanks for sharing.

soto97 commented May 31, 2013

That worked beautifully. Thanks for sharing.

@sean-duffy

This comment has been minimized.

Show comment Hide comment
@sean-duffy

sean-duffy Jan 4, 2014

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!

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!

@swinggraphics

This comment has been minimized.

Show comment Hide comment
@swinggraphics

swinggraphics Feb 10, 2014

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."

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."

@nslater

This comment has been minimized.

Show comment Hide comment
@nslater

nslater Feb 12, 2014

@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.

Owner

nslater commented Feb 12, 2014

@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.

@tbrown

This comment has been minimized.

Show comment Hide comment
@tbrown

tbrown Apr 15, 2014

Thanks for this, Noah! Very helpful.

tbrown commented Apr 15, 2014

Thanks for this, Noah! Very helpful.

@adkelley

This comment has been minimized.

Show comment Hide comment
@adkelley

adkelley May 15, 2014

Thank you!

Thank you!

@alvarogois

This comment has been minimized.

Show comment Hide comment
@alvarogois

alvarogois Aug 29, 2014

Awesome. Thanks!

Awesome. Thanks!

@rahulvohra

This comment has been minimized.

Show comment Hide comment
@rahulvohra

rahulvohra Jan 30, 2015

Great, thanks!

Great, thanks!

@patrickgrady

This comment has been minimized.

Show comment Hide comment
@patrickgrady

patrickgrady Apr 13, 2015

This is great, thank you!

This is great, thank you!

@samyakbhuta

This comment has been minimized.

Show comment Hide comment
@samyakbhuta

samyakbhuta May 2, 2015

The code is 54 words, 386 characters :)

The code is 54 words, 386 characters :)

@dieguico

This comment has been minimized.

Show comment Hide comment
@dieguico

dieguico Aug 1, 2015

Nice job! :)

dieguico commented Aug 1, 2015

Nice job! :)

@rhein

This comment has been minimized.

Show comment Hide comment
@rhein

rhein Sep 2, 2015

Just what I need x times a day and always ended up using a text editor, thanks!

rhein commented Sep 2, 2015

Just what I need x times a day and always ended up using a text editor, thanks!

@danielfelipe113

This comment has been minimized.

Show comment Hide comment
@danielfelipe113

danielfelipe113 Sep 12, 2015

Thanks! Very usefull

Thanks! Very usefull

@zagen

This comment has been minimized.

Show comment Hide comment
@zagen

zagen Oct 28, 2015

Very nice. Thanks.

zagen commented Oct 28, 2015

Very nice. Thanks.

@darkarconio

This comment has been minimized.

Show comment Hide comment
@darkarconio

darkarconio Oct 29, 2015

This is awesome, thank you!

This is awesome, thank you!

@deikka

This comment has been minimized.

Show comment Hide comment
@deikka

deikka Feb 1, 2016

Cool! Thanks

deikka commented Feb 1, 2016

Cool! Thanks

@ngemily

This comment has been minimized.

Show comment Hide comment
@ngemily

ngemily Mar 6, 2016

Excellent! Thanks for the code and the detailed instructions.

ngemily commented Mar 6, 2016

Excellent! Thanks for the code and the detailed instructions.

@markschwarz

This comment has been minimized.

Show comment Hide comment
@markschwarz

markschwarz Jun 27, 2016

Thanks! I use this for checking simplicity of my writing. I added some very messaging to make rough sentence count and speaking time more accessible.
https://gist.github.com/markschwarz/f5ca58712034bcd5d3d91084eb71da4d

Thanks! I use this for checking simplicity of my writing. I added some very messaging to make rough sentence count and speaking time more accessible.
https://gist.github.com/markschwarz/f5ca58712034bcd5d3d91084eb71da4d

@mec

This comment has been minimized.

Show comment Hide comment
@mec

mec Jul 7, 2016

So, nice and simple - thanks for sharing!

mec commented Jul 7, 2016

So, nice and simple - thanks for sharing!

@voluntaryistonly

This comment has been minimized.

Show comment Hide comment
@voluntaryistonly

voluntaryistonly May 2, 2017

Hi Love the Script, been using it for sometime now, just today came across a problem, the script stopped working & i get the following error messages:
1st alert window: "there was a problem with the input to the service" with 2 option buttons: "show workflow" & "ok"
2nd alert window: The "Word and Character Counter" service could not be used with 2 option buttons: "show workflow" & "ok"
I have checked the workflow, it is exactly as is listed above, device: mac mini, running latest version of El Capitan (10.11.6)
I could provide the console log, if you tell me what to look for (sorry not so techno)
thanks in advance,
regards
vm
ps: on firefox 53.0 (64bit) doesn't give error messages on other apps

voluntaryistonly commented May 2, 2017

Hi Love the Script, been using it for sometime now, just today came across a problem, the script stopped working & i get the following error messages:
1st alert window: "there was a problem with the input to the service" with 2 option buttons: "show workflow" & "ok"
2nd alert window: The "Word and Character Counter" service could not be used with 2 option buttons: "show workflow" & "ok"
I have checked the workflow, it is exactly as is listed above, device: mac mini, running latest version of El Capitan (10.11.6)
I could provide the console log, if you tell me what to look for (sorry not so techno)
thanks in advance,
regards
vm
ps: on firefox 53.0 (64bit) doesn't give error messages on other apps

@s0apii

This comment has been minimized.

Show comment Hide comment
@s0apii

s0apii Mar 7, 2018

Awesome, thank you!

s0apii commented Mar 7, 2018

Awesome, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment