4 Replies Latest reply: Jan 18, 2008 9:17 PM by Charles Minow
Dylanmusic Level 1 Level 1 (0 points)
How do you count the number of words in a "Text Edit" document?

iMAC G5 20", Mac OS X (10.4.9), the usual stuff!
  • 1. Re: TextEdit word count
    Niel Level 10 Level 10 (242,110 points)
    Open the Script Editor in the /Applications/AppleScript/ folder and run the following:

    tell application "TextEdit"
    count words of document 1
    end tell

    (27840)
  • 2. Re: TextEdit word count
    pejrm Level 1 Level 1 (0 points)
    Brilliant, thank you very much. That script works really well.
  • 3. Re: TextEdit word count
    sudoku Level 1 Level 1 (0 points)
    Thank you, Niel, for the exact answer that I needed at the exact time! Thanks also to the users who asked the question. One point: After i got my word count using your instructions, I decided to see what a right-click in the open Script application would tell me and I found one crucial difference: In the first menu after right-clicking, I hit "tell blocks," then clicked again and got "tell application." The wording that pops up matches yours, except for that numeral 1, and without the 1, the script does not work for me. Just wondering: Does the character have to be a 1, or would other characters work too?
  • 4. Re: TextEdit word count
    Charles Minow Level 6 Level 6 (9,190 points)
    sudoku--

    except for that numeral 1, and without the 1, the script does not work for me. Just wondering: Does the character have to be a 1, or would other characters work too?


    The numeral "1" is a way of identifying which document window TextEdit should count the words in. Try this: create a second document in TextEdit with a different number of words in it. Now go back to the script editor and change the "1" back and forth to a "2". You'll get different answers, depending on which window is the frontmost in the TextEdit. They're identified with "1" as the frontmost, "2" as the second, and so on if there are more windows.

    charlie