Word count for TextEdit

I don’t know if anyone else has been wondering why Apple left a word count feature out of TextEdit but I certainly have been. Granted I have a couple word processors that are chock full of cool features including a word count but sometimes I like to use TextEdit because it is lightweight, simple and fast.

Anyway, I asked Google about a word count feature for TextEdit and one of the results was this easy Applescript option that works pretty well even if it involves running the script as a separate item to TextEdit. To run this you need to open the Script Editor in the /Applications/AppleScript/ folder:

tell application “TextEdit”
count words of document 1
end tell

Thanks to Niel for posting the solution.


Technorati Tags:
, ,


Posted

in

by

Tags:

Comments

  1. Martin Michel avatar

    Hi Paul,

    your code example sometimes returns strange results. For example, it returns 10 words for a document which in fact contains 100 words. So I enhanced your script a bit and came up with the following version:

    tell application "TextEdit"

    activate

    set doccont to text of document 1

    set docname to name of document 1

    set wordcount to length of (words of doccont)

    set paracount to length of (paragraphs of doccont)

    display dialog "The frontmost document* contains:" & return & return & "Words: " & wordcount & return & "Paragraphs: " & paracount & return & return & "* " & docname buttons {"OK"} default button 1 with title "Text infos for TextEdit"

    end tell

    This one also counts the paragraphs.

    Best regards to South Africa from Germany!

  2. Martin Michel avatar

    Hi Paul,

    your code example sometimes returns strange results. For example, it returns 10 words for a document which in fact contains 100 words. So I enhanced your script a bit and came up with the following version:

    tell application "TextEdit"

    activate

    set doccont to text of document 1

    set docname to name of document 1

    set wordcount to length of (words of doccont)

    set paracount to length of (paragraphs of doccont)

    display dialog "The frontmost document* contains:" & return & return & "Words: " & wordcount & return & "Paragraphs: " & paracount & return & return & "* " & docname buttons {"OK"} default button 1 with title "Text infos for TextEdit"

    end tell

    This one also counts the paragraphs.

    Best regards to South Africa from Germany!

  3. Martin Michel avatar

    Hi Paul,

    your code example sometimes returns strange results. For example, it returns 10 words for a document which in fact contains 100 words. So I enhanced your script a bit and came up with the following version:

    tell application "TextEdit"

    activate

    set doccont to text of document 1

    set docname to name of document 1

    set wordcount to length of (words of doccont)

    set paracount to length of (paragraphs of doccont)

    display dialog "The frontmost document* contains:" & return & return & "Words: " & wordcount & return & "Paragraphs: " & paracount & return & return & "* " & docname buttons {"OK"} default button 1 with title "Text infos for TextEdit"

    end tell

    This one also counts the paragraphs.

    Best regards to South Africa from Germany!

  4. Martin Michel avatar

    Hi Paul,

    your code example sometimes returns strange results. For example, it returns 10 words for a document which in fact contains 100 words. So I enhanced your script a bit and came up with the following version:

    tell application "TextEdit"

    activate

    set doccont to text of document 1

    set docname to name of document 1

    set wordcount to length of (words of doccont)

    set paracount to length of (paragraphs of doccont)

    display dialog "The frontmost document* contains:" & return & return & "Words: " & wordcount & return & "Paragraphs: " & paracount & return & return & "* " & docname buttons {"OK"} default button 1 with title "Text infos for TextEdit"

    end tell

    This one also counts the paragraphs.

    Best regards to South Africa from Germany!

  5. Paul avatar

    Ooh, fantastic, thanks very much. I'll try that out!

  6. Paul avatar

    Ooh, fantastic, thanks very much. I’ll try that out!

  7. Paul avatar

    Ooh, fantastic, thanks very much. I’ll try that out!

  8. Paul avatar

    Ooh, fantastic, thanks very much. I’ll try that out!

  9. Business Entertainment Free avatar

    Tips for hurdle free Bad Credit Business Loans…

    Are you as a business person thinking that your bad credit may come in the way of borrowing from a professional lender? Well you need not to worry at all as there are many lenders around who are devoted to bad credit business loans….

  10. Tips for hurdle free Bad Credit Business Loans…

    Are you as a business person thinking that your bad credit may come in the way of borrowing from a professional lender? Well you need not to worry at all as there are many lenders around who are devoted to bad credit business loans….

  11. Joshua avatar

    If you use Quicksilver and invoke the script through it, it will run and tell you how many words are in the document. This is no big extra, but seems more convenient than keeping Script Editor open.

    This is really a great script. Thank you Martin, Niel, et al. for the great work!

  12. Joshua avatar

    If you use Quicksilver and invoke the script through it, it will run and tell you how many words are in the document. This is no big extra, but seems more convenient than keeping Script Editor open.

    This is really a great script. Thank you Martin, Niel, et al. for the great work!

  13. Joshua avatar

    If you use Quicksilver and invoke the script through it, it will run and tell you how many words are in the document. This is no big extra, but seems more convenient than keeping Script Editor open.

    This is really a great script. Thank you Martin, Niel, et al. for the great work!

  14. Joshua avatar

    If you use Quicksilver and invoke the script through it, it will run and tell you how many words are in the document. This is no big extra, but seems more convenient than keeping Script Editor open.

    This is really a great script. Thank you Martin, Niel, et al. for the great work!

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.