Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Apple Script to count characters in TextEdit

Apple Script to count characters in TextEdit
Thread Tools
Professional Poster
Join Date: Feb 2002
Location: adequate, thanks.
Status: Offline
Reply With Quote
Feb 14, 2003, 12:36 PM
 
Anyone knows how to mak an Apple Script that counts the characters in TextEdit? I have almost no clue how to do this, although I know Apple Script can be very simple to learn... Oh, I'm lazy...
     
JKT
Professional Poster
Join Date: Jan 2002
Location: London, UK
Status: Offline
Reply With Quote
Feb 14, 2003, 12:49 PM
 
Originally posted by andreas_g4:
Anyone knows how to mak an Apple Script that counts the characters in TextEdit? I have almost no clue how to do this, although I know Apple Script can be very simple to learn... Oh, I'm lazy...
Nope, but I do know of a Service that offers this as one of many features:

WordService
     
Mac Elite
Join Date: May 2001
Status: Offline
Reply With Quote
Feb 14, 2003, 12:58 PM
 
Use "wc" in the terminal to count the number of lines, words, and bytes in a text file.

-
     
Addicted to MacNN
Join Date: Apr 2001
Location: europe
Status: Offline
Reply With Quote
Feb 14, 2003, 01:15 PM
 
tell application "TextEdit"
set theText to the text of the document 1
set theCharCount to the length of the theText
display dialog "The text of the document \"" & (the name of the window 1) & "\" contains " & theCharCount & " characters." buttons {"OK"}
end tell
Nasrudin sat on a river bank when someone shouted to him from the opposite side: "Hey! how do I get across?" "You are across!" Nasrudin shouted back.
     
Addicted to MacNN
Join Date: Apr 2001
Location: europe
Status: Offline
Reply With Quote
Feb 14, 2003, 01:41 PM
 
This one shouldn't count whitespace:


tell application "TextEdit"
set theText to the text of document 1
set theWordCount to the count of words of theText
set theCharCount to 0
repeat with i from 1 to the theWordCount
set theCharCount to theCharCount + the (length of the word i of theText)
end repeat
display dialog "The text of the document \"" & (the name of the window 1) & ¬
"\" contains " & theWordCount & " words and " & theCharCount & " characters." buttons {"OK"}
end tell
Nasrudin sat on a river bank when someone shouted to him from the opposite side: "Hey! how do I get across?" "You are across!" Nasrudin shouted back.
     
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
Feb 14, 2003, 01:50 PM
 
tell original poster
topic is not "Mac OS X"
move topic to "Software"
end tell
     
Addicted to MacNN
Join Date: Apr 2001
Location: europe
Status: Offline
Reply With Quote
Feb 14, 2003, 01:56 PM
 
wataru, AppleScript is part of the system in my opinion (as is TextEdit).
(Last edited by Developer; Feb 14, 2003 at 02:10 PM. )
Nasrudin sat on a river bank when someone shouted to him from the opposite side: "Hey! how do I get across?" "You are across!" Nasrudin shouted back.
     
Mac Elite
Join Date: May 2001
Status: Offline
Reply With Quote
Feb 14, 2003, 02:03 PM
 
... but TextEdit isn't

-
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:41 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2