1vp_spec( 2 :superMenuTitle => "R Word Count", 3 :menuTitle => "R In Document" ) 4 5vp_action do |windowController| 6 7 totalPageCount = 0 8 totalWordCount = 0 9 10 sc = OSX::NSSpellChecker.sharedSpellChecker 11 document = windowController.document 12 13 document.keys.each do |pageKey| 14 page = document.pageForKey(pageKey) 15 16 # voodoopad 3.0 supports multiple types of pages. So we make sure 17 # it's a regular page type first. 18 # if page.oc_type == OSX::VPPageType then 19 if page.oc_type.to_s == 'page' then 20 attString = page.dataAsAttributedString 21 pageText = attString.string 22 totalWordCount += sc.countWordsInString_language(pageText, sc.language) 23 totalPageCount += 1 24 end 25 end 26 27 s = format("There are %d words in %d pages", totalWordCount, totalPageCount) 28 OSX.NSRunAlertPanel("Document word count", s, nil, nil, nil) 29end 30