I'm a beginner AppleScripter, so I'm absolutely sure there are more efficient ways to implement this, but I hacked the following together. It's a modified "ListNext.scpt" script from this thread, with:
Anyway, here it is - hopefully, someone might find it as useful as I have:
- Bubble Sort by due date
- intelligent sorting of items without a Due Date
- merging of tasks by section
- shell output (for GeekTool friendliness!)
Anyway, here it is - hopefully, someone might find it as useful as I have:
Code:
on run set strList to "" tell application "OmniFocus" set oDoc to default document set lstSections to every section of oDoc set strList to my ListSections(lstSections, strList) end tell -- split the list by line set arrayList to split(strList, return) -- sort the list BubbleSort(arrayList) set strCmd to "" repeat with strTask in arrayList try set strDate to item 1 of (split(strTask, "|")) set strName to item 2 of (split(strTask, "|")) if strDate is not "" then set strCmd to strCmd & strDate & ": " & strName & return else set strCmd to strCmd & strName & return end if end try end repeat set strCmd to ("echo " & strCmd) do shell script strCmd end run on ListSections(lstSections, strList) using terms from application "OmniFocus" repeat with oSectn in lstSections if class of oSectn is project then -- ANY TASKS OF PROJECT set lstTasks to every task of oSectn if lstTasks ≠ {} then set strList to my ListTasks(lstTasks, strList) end if else -- FOLDER --set strList to strList & name of oSectn & return -- ANY CONTENTS OF FOLDER set lstSubSections to every section of oSectn if lstSubSections ≠ {} then set strList to my ListSections(lstSubSections, strList) end if end if end repeat end using terms from return strList end ListSections on ListTasks(lstTasks, strList) using terms from application "OmniFocus" repeat with oTask in lstTasks --TASK if next of oTask and not completed of oTask then tell oTask set dteDue to due date try dteDue set strList to strList & short date string of dteDue end try set strList to strList & "|[" & name of containing project & "] " & name & return end tell end if -- ANY SUB-TASKS set lstSubTasks to every task of oTask if lstSubTasks ≠ {} then set strList to my ListTasks(lstSubTasks, strList) end if end repeat end using terms from return strList end ListTasks to split(someText, delimiter) set AppleScript's text item delimiters to delimiter set someText to someText's text items set AppleScript's text item delimiters to {""} --> restore delimiters to default value return someText end split on BubbleSort(theList) set FAILED_COERCION to -1700 if class of theList is list then set theSize to length of theList repeat with i from 1 to theSize repeat with j from 2 to (theSize - i + 1) try set strDate1 to item 1 of (split((item j of theList), "|")) set strDate2 to item 1 of (split((item (j - 1) of theList), "|")) try if (date strDate2 > date strDate1) then set temp to (item (j - 1) of theList) set (item (j - 1) of theList) to (item j of theList) set (item j of theList) to temp end if on error number FAILED_COERCION set temp to (last item of theList) set (last item of theList) to (item j of theList) set (item j of theList) to temp end try end try end repeat end repeat return theList else return false end if end BubbleSort on replaceText(theText, swapOut, swapIn) (* This bit comes from Apple's own "Replace Text in Item Names" script with some of the variables changed to make it a call-able handler *) if the theText contains the swapOut then -- replace target string using delimiters set AppleScript's text item delimiters to the swapOut set the text_item_list to every text item of theText set AppleScript's text item delimiters to the swapIn set the theText to the text_item_list as string set AppleScript's text item delimiters to "" end if return theText end replaceText