The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Does context totaler script exits? (http://forums.omnigroup.com/showthread.php?t=30332)

thart 2013-07-14 06:45 AM

Does context totaler script exits?
 
In vain I have searched this wonderful forum for any simple script that would create a table of context totals.

Ideally it would be similar to script & table found in this thread which I use extensively:

[url]http://forums.omnigroup.com/showthread.php?t=18405&highlight=Statistics[/url]

What I am envisioning is something along the following lines for each individual context:
@Call = 15
@Mac = 49
@Waiting for = 209
etc.

[I]Question[/I]: Does this script exist already or is it easily created?

Thank you in advance.

RobTrew 2013-07-14 01:30 PM

The basics might look something like this:

[CODE]property pTitle : "Remaining task count for each context"
property pVer : "0.01"
property pPrefix : "@"
property pDelim : tab

property pblnToClipboard : true

set str to ""
tell application id "OFOC"
tell default document
set {lstName, lstCount} to {name, remaining task count} of flattened contexts
repeat with i from 1 to length of lstName
set str to (str & pPrefix & item i of lstName & pDelim & (item i of lstCount) as string) & linefeed
end repeat
if pblnToClipboard then set the clipboard to str
end tell
end tell

display dialog str buttons {"OK"} default button "OK" with title pTitle & " ver. " & pVer[/CODE]

kingsinger 2013-07-14 01:47 PM

Curt Clifton made a widget that does something like this, if memory serves.

It's called wheretofocus. I think you can get it here.

[URL="http://www.curtclifton.net/projects/"]
http://www.curtclifton.net/projects/[/URL]

RobTrew 2013-07-14 02:19 PM

[QUOTE=RobTrew;126167]The basics might look something like this:[/QUOTE]

Though it might make more sense to reproduce the nesting of the context tree, to show where a parent count includes summing of descendant counts:

[CODE]property pTitle : "Remaining task count for each context"
property pVer : "0.02"
property pPrefix : "@"
property pDelim : " "
property pIndent : tab

property pblnToClipboard : true

on run
tell application id "OFOC" to set str to my ListContexts(contexts of default document, "")

display dialog str buttons {"OK"} default button "OK" with title pTitle & " ver. " & pVer
end run

on ListContexts(lstContexts, strIndent)
set str to ""
tell application id "OFOC"
repeat with oContext in lstContexts
tell oContext
set str to str & strIndent & pPrefix & its name & pDelim & (remaining task count as string) & linefeed
set lstChiln to contexts
if lstChiln ≠ {} then set str to str & my ListContexts(lstChiln, strIndent & pIndent)
end tell
end repeat
return str
end tell
end ListContexts
[/CODE]

RobTrew 2013-07-16 03:27 AM

[QUOTE=RobTrew;126169]to show where a parent count includes summing of descendant counts[/QUOTE]

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).

[CODE]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)"
else
set strSubTotal to ""
end if
else
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
[/CODE]

thart 2013-07-16 06:23 PM

RobTrew,

Spot on script. Thank you very much. I do appreciate your quick & effective response.

Regards,
Todd

RobTrew 2013-07-16 10:37 PM

Good - I'm glad that meets the need.

Tidied up a little here for legibility, in case you need to adjust it.

(Forum settings no longer permit updating earlier posts)

[CODE]property pTitle : "Remaining task counts for contexts"
property pVer : "0.04"
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
-- COUNT AND REPORT FOR SUB-TREE
set {strSub, lngSub} to my ListContexts(contexts, strIndent & pIndent)

-- COUNT ASSIGNMENTS TO THIS LEVEL (SUBTRACTING SUBTREE ASSIGNMENTS)
set lngCount to remaining task count
set lngThisLevel to lngCount - lngSub

-- REPORT ON THIS LEVEL, APPENDING SUB-TREE REPORT
set strSubTotal to ""
if (pblnSubTreeCounts and (lngSub > 0)) then set strSubTotal to " (+" & (lngSub as string) & " in sub contexts)"
set str to (str & strIndent & pPrefix & its name & pDelim & lngThisLevel as string) & strSubTotal & linefeed & strSub
end tell

-- AND KEEP A RUNNING TALLY FOR REPORTING TO THE LEVEL ABOVE
set lngTotal to lngTotal + lngCount
end repeat
return {str, lngTotal}
end tell
end ListContexts
[/CODE]


All times are GMT -8. The time now is 01:02 AM.

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