1vp_spec(
2  :superMenuTitle => "R Word Count",
3       :menuTitle => "R In Page" )
4
5vp_action do  |windowController|
6
7  textView  = windowController.textView
8  text      = textView.textStorage.string
9  sc        = OSX::NSSpellChecker.sharedSpellChecker
10  wordCount = sc.countWordsInString_language(text, sc.language)
11
12  lText       = text.to_s.gsub(/\r\n/, "\n").gsub(/\r/, "\n")
13
14  letterCount = lText.split(//).size
15  lineCount   = lText.split("\n").size
16
17  s = format("%d words.\n%d lines.\n%d letters.", 
18             wordCount, lineCount, letterCount)
19  OSX.NSRunAlertPanel("Word Count", s, nil, nil, nil)
20end
21