The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniOutliner > OmniOutliner 3 for Mac
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Word Count Revisited Thread Tools Search this Thread Display Modes
An updated 003 word-count script which:
  1. Gives separate and aggregated word counts for all rich text columns (and notes)
  2. Reports separate word counts for: all rows, visible rows, and selected rows
  3. Offers, in the report dialog, to copy the report into the clipboard (with timestamp and filename)

(The distinction between visible and invisible rows makes it possible to get word-counts for particular sections or sub-sections selected in the utility panel, and to get differing word counts for various levels of outline collapse)

(As with the previous draft, this approach of getting lists of property values from a reference yields much faster word counts than the iterative scripts first posted in 2008)



Code:
-- Ver 0.7  
-- Gives word count for: all rows, visible rows, selected rows, 
-- and for each rich text column (and notes), as well as totals
-- Report dialog offers option of copying report to clipboard
-- (with datestamp and filename)

property pstrOfferCopy : "Copy report to clipboard"
property pDelim : space
property pEOL : return & return

on run
	tell application id "com.omnigroup.OmniOutlinerPro3"
		try
			activate
			set oDoc to front document
		on error
			return
		end try
		
		-- Ensure that text item delimiter is SPACE
		-- and prepare to restore any other value at the end of the script
		set strDelim to my text item delimiters
		set my text item delimiters to pDelim
		
		tell front document
			-- DEFINE SETS OF ROWS TO REPORT ON
			
			-- All rows by default
			set refAllRows to a reference to rows
			set lngRows to count of refAllRows
			set lstRowSets to {{"all", refAllRows}}
			
			-- Plus visible rows if any are hidden
			set refVisblRows to a reference to (rows where visible is true)
			set lngVisible to count of refVisblRows
			if lngVisible is not lngRows then 
				set end of lstRowSets to {"visible", refVisblRows}
			
			-- Plus selected rows if any are selected
			set refSeldRows to a reference to selected rows
			set lngSeldRows to count of refSeldRows
			if lngSeldRows > 0 then 
				set end of lstRowSets to {"selected", refSeldRows}
			
			-- ASSEMBLE A LIST OF ALL RICH TEXT FIELDS (INCLUDING NOTES)
			set refCols to a reference to (columns where type is rich text)
			set lstColNames to name of refCols
			if first item of lstColNames is "" then set first item of lstColNames to "Notes"
			set lstColIDs to id of refCols
			set lngCols to length of lstColIDs
			
			-- COLLECT THE WORD COUNTS FOR ROW SETS & COLUMNS, WITH TOTALS
			set lstData to {}
			repeat with iRowSet from 1 to length of lstRowSets
				set {strSetName, refSet} to item iRowSet of lstRowSets
				set lstSet to {{strSetName, count of refSet}}
				set intSetWords to 0
				repeat with iCol from 1 to lngCols
					-- Count words in this column
					set strId to item iCol of lstColIDs
					set lstColText to value of cell id strId of refSet
					set intColWords to count of words of (lstColText as text)
					-- Record the column name and word count
					set end of lstSet to {item iCol of lstColNames, intColWords}
					-- Increment the total word count
					set intSetWords to intSetWords + intColWords
				end repeat
				set end of lstSet to {"total", intSetWords}
				set end of lstData to lstSet
			end repeat
		end tell
	end tell
	
	-- BUILD A LEGIBLE REPORT FOR THE USER
	set strMsg to ""
	set intCols to (length of (first item of lstData)) - 1
	
	-- A REPORT FOR EACH SET OF ROWS
	repeat with iRowSet from 1 to length of lstData
		set lstSetData to item iRowSet of lstData
		set {strSetName, lngRows} to first item of lstSetData
		set lngTotal to last item of last item of lstSetData
		set strMsg to strMsg & lngTotal & pl(lngTotal, "word") & " in " & strSetName & " rows" & tab & "(" & lngRows & " " & pl(lngRows, "row") & ")" & return
		-- WITH A SUB-REPORT FOR EACH RICH TEXT COLUMN (INCLUDING NOTES)
		repeat with iCol from 2 to intCols
			set {strColName, intColWords} to item iCol of lstSetData
			set strMsg to strMsg & tab & strColName & ": " & intColWords & pl(intColWords, "word") & return
		end repeat
		set strMsg to strMsg & return
	end repeat
	
	set my text item delimiters to strDelim
	
	tell me
		activate
		set recResponse to display dialog strMsg buttons {pstrOfferCopy, "OK"} with icon 1 with title ("WORD COUNT")
		if button returned of recResponse is pstrOfferCopy then 
			tell application id "com.apple.finder" to set the clipboard to ((current date) as string) & return & name of oDoc & return & return & strMsg
	end tell
end run

-- Pluralize word unless lngQuant is 1
on pl(lngQuant, strWord)
	if lngQuant is 1 then return " " & strWord
	" " & strWord & "s"
end pl

Last edited by RobTrew; 2010-06-25 at 10:46 AM..
 
Thank you very much RobinTrew.

I have just come back after some months to see if there has been development with the Word Count and in fact this script of your is quite superb.

I tend to have the actual text for the essay in one column, then a neighbouring column has notes etc. I can use your word count script to get me a count of just the column with the text of the article alone.
 
Good ! I'm glad it's proving useful.
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
OmniGraffle Word Count RobTrew OmniGraffle General 2 2010-10-04 01:48 PM
Checklists, revisited Arild OmniFocus 1 for Mac 5 2010-06-08 07:26 AM
Word Count and Statistics Patrick J OmniOutliner 3 for Mac 7 2009-04-20 10:50 PM
Word Count Patrick J OmniOutliner 3 for Mac 0 2007-10-20 09:40 AM
Word Count m_s OmniOutliner 3 for Mac 0 2006-10-25 03:49 AM


All times are GMT -8. The time now is 07:21 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.