Sample Header Ad - 728x90

Automator: Error when running a Word Count service in TextEdit

1 vote
2 answers
113 views
I followed a brief [step-by-step guide](https://www.macworld.com/article/672819/) for adding **word count** functionality to **TextEdit**. Note that the guide instructs: "It will ask you to choose a type for your document; click **Service**". However, probably due to version differences, instead one must choose **Quick Action**. As the guide advises, I used this code: osascript 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 AppleScriptHereDoc After creating the Action / Service and running it, I get the following error: The action “Run Shell Script” encountered an error: “-: -c: line 0: syntax error near unexpected token `(' -: -c: line 0: `osascript 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 AppleScriptHereDoc'” The guide is from Feb 23, 2018 (over 5 years ago at the time of this writing), so that may have something to do with it. Hopefully there's a simple fix though.
Asked by Mentalist (1360 rep)
May 1, 2023, 05:15 AM
Last activity: May 24, 2025, 07:55 PM