こんにちは
ご指摘のJavascriptを用いた文字数カウンタと類似する機能のAppleScript例を下記に示します。
参考になれば幸いです。
--
on run
tell application "TextEdit"
set theText to the text of document 1
set word_count to count words of document 1
set char_count to count characters of document 1
set para_count to count paragraphs of document 1
end tell
set theLF to ASCII character 10
set LF_count to countSubstring(theText, theLF)
set space_count to countSubstring(theText, " ")
set show_words to "文字数:" & (char_count as string) & return & "改行を除いた文字数:" & ((char_count - LF_count) as string) & return & "空白、改行を除いた文字数:" & ((char_count - space_count - LF_count) as string) & return & "行数:" & (para_count as string)
set dialog_title to "TextEdit Word Count"
display dialog show_words with icon 1 with title dialog_title buttons {"OK"} default button "Ok"
end run
-- e.g. countSubstring("abc abc abc", "abc") --> 3
on countSubstring(theText, theSubstring)
-- ljr (http://applescript.bratis-lover.net/library/string/), modified from Aurelio.net (http://aurelio.net/doc/as4pp.html)
local ASTID, theText, theSubstring, i
set ASTID to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to theSubstring
set i to (count theText's text items) - 1
set AppleScript's text item delimiters to ASTID
return i
on error eMsg number eNum
set AppleScript's text item delimiters to ASTID
error "Can't countSubstring: " & eMsg number eNum
end try
end countSubstring
--
参考文献:
http://applescript.bratis-lover.net/library/string/#countSubstring
http://hints.macworld.com/article.php?story=20070730101510623
動作環境:
-Mac OSX 10.6.8 Snow Leopard
-AppleScriptエディタ 2.3(118) / AppleScript 2.1.2
-テキストエディット 1.6(264)