View Single Post
Originally Posted by RobTrew View Post
to show where a parent count includes summing of descendant counts
You could also separate the count of tasks specifically assigned to a parent level from the sum of tasks assigned to descendant levels.

(And display a global total).

property pTitle : "Remaining task counts for contexts"
property pVer : "0.03"
property pPrefix : "@"
property pDelim : "  "
property pIndent : tab

property pblnToClipboard : true
property pblnSubTreeCounts : true

on run
	tell application id "OFOC" to set {str, lngTotal} to my ListContexts(contexts of default document, "")
	set str to str & linefeed & "TOTAL: " & lngTotal as string
	if pblnToClipboard then set the clipboard to str
	display dialog str buttons {"OK"} default button "OK" with title pTitle & "  ver. " & pVer
end run

on ListContexts(lstContexts, strIndent)
	set {str, lngCount, lngTotal} to {"", 0, 0}
	tell application id "OFOC"
		repeat with oContext in lstContexts
			tell oContext
				set lngCount to remaining task count
				set lngTotal to lngTotal + lngCount
				set {strSub, lngSub} to my ListContexts(contexts, strIndent & pIndent)
				set lngThisLevel to lngCount - lngSub
				if pblnSubTreeCounts then
					if lngSub > 0 then
						set strSubTotal to "  (+" & (lngSub as string) & " in sub contexts)"
						set strSubTotal to ""
					end if
					set strSubTotal to ""
				end if
				set str to (str & strIndent & pPrefix & its name & pDelim & lngThisLevel as string) & strSubTotal & linefeed & strSub
			end tell
		end repeat
		return {str, lngTotal}
	end tell
end ListContexts