This script reports "active" tasks, defined as those that are flagged and not completed. The output format is as
HEADER (COUNT)
BAR
PRE-STRING context SEPARATER task
...
Action groups can be displayed expanded or not, whereby in the latter case they show as
Project Group SEPARATER group name <COUNT>
Tasks with empty contexts show as
PRE-STRING <empty> SEPARATER task
The report can be sorted forward or reverse, and counts can be hidden. I use this with GeekTool -- caveat OF must be running for it to work. The script is attached in an archive.
Code:
(*
This script creates a list of flagged actions and reports them in (reverse) order by context
Report Format
NOHEADER
or
HEADER (COUNT)
BAR
PRESTRING context SEPARATOR task
...
*)
property reverseSort : "true" -- set to false for forward sort
property showCount : "true" -- set to false to avoid showing count
property expandGroup : "true" -- set to true to expand action groups
property headerStr : "Active" -- HEADER text when active count > 0
property nheaderStr : "No Active Tasks" -- NOHEADER when active count = 0
property mtcntxtStr : "<empty>" -- string when context is missing
property barStr : "--" -- BAR string after header
property preStr : "●" & tab -- PRESTRING prior to each list item
property actGroupStr : "Project Group" -- pre-string when task is action group (shows when expandGroup = false)
property sepStr : " : " -- SEPARATOR string between context and task
tell application "OmniFocus"
tell front document
-- get list of active tasks
set AList to flattened tasks where ((flagged is true) and (completed is false))
if ((count of AList) > 0) then
-- make the header
set theCount to (count of AList)
set SortedList to ""
set theReport to ""
-- start parsing each task
repeat with ListItem in AList
if (the number of tasks of ListItem = 0) then
-- a single task
try
set theContext to preStr & (name of context of ListItem) & sepStr
on error
set theContext to preStr & mtcntxStr & sepStr
end try
set theAction to (name of ListItem)
set SortedList to SortedList & (theContext & theAction) as list
else
-- an action group (no expand or expand)
if (expandGroup is "false") then
-- do not expand action groups
if (showCount is "true") then
set countStr to " <" & (number of tasks of ListItem) & ">"
else
set countStr to ""
end if
set theContext to preStr & actGroupStr & sepStr
set theAction to (name of containing project of ListItem) & sepStr & (name of ListItem) & countStr
set SortedList to SortedList & (theContext & theAction) as list
else
-- expand action groups completely
set XList to ((flattened tasks of ListItem) where (completed is false))
set theCount to theCount - 1
repeat with XListItem in XList
try
set theContext to preStr & (name of context of XListItem) & sepStr
on error
set theContext to preStr & mtcntxtStr & sepStr
end try
set theAction to (name of XListItem)
set theCount to theCount + 1
set SortedList to SortedList & (theContext & theAction) as list
end repeat
end if
end if
end repeat
if (reverseSort is "true") then
set SortedList to the reverse of my simple_sort(the SortedList)
else
set SortedList to my simple_sort(the SortedList)
end if
repeat with ListItem in SortedList
set theReport to theReport & (ListItem) & return
end repeat
else
set theReport to nheaderStr
end if
end tell
if (showCount is "true") then
set countStr to " (" & theCount & ")"
else
set countStr to ""
end if
set theReport to headerStr & countStr & return & barStr & return & theReport
return theReport
end tell
on simple_sort(my_list)
set the index_list to {}
set the sorted_list to {}
repeat (the number of items in my_list) times
set the low_item to ""
repeat with i from 1 to (number of items in my_list)
if i is not in the index_list then
set this_item to item i of my_list as text
if the low_item is "" then
set the low_item to this_item
set the low_item_index to i
else if this_item comes before the low_item then
set the low_item to this_item
set the low_item_index to i
end if
end if
end repeat
set the end of sorted_list to the low_item
set the end of the index_list to the low_item_index
end repeat
return the sorted_list
end simple_sort