View Single Post
PS to add a total to the header in some kind of bash version (to reduce any performance hit on the OF app, or to continue displaying lists when OF isn't running) you could do something like:

Code:
#!/bin/sh
#OFOC=$(osascript -e 'tell application "Finder" to get id of application file id "OFOC"')
OFOC="com.omnigroup.OmniFocus" # For Appstore-purchased variant use (slower) line above instead
OFQUERY="sqlite3 $HOME/Library/Caches/$OFOC/OmniFocusDatabase2"
NOW=$($OFQUERY "SELECT (strftime('%s','now','localtime'))")
YEARZERO=$($OFQUERY "SELECT strftime('%s','2001-01-01')")

MATCHES="t.flagged=1 and t.dateCompleted is null 
	and (t.effectiveDateToStart is null 
	or ($YEARZERO + t.effectiveDateToStart) < $NOW)"

TOTAL=$($OFQUERY "SELECT count(*) FROM task t WHERE $MATCHES")

echo "FLAGGED AND NEITHER COMPLETED NOR DEFERRED ($TOTAL tasks):"
$OFQUERY "SELECT c.name, p.name, t.name
FROM ((task tt left join projectinfo pi on tt.containingprojectinfo=pi.pk) t 
left join task p on t.task=p.persistentIdentifier) 
left join context c on t.context = c.persistentIdentifier
WHERE $MATCHES
ORDER BY c.name, p.name"| awk '
BEGIN {FS="\|"; prj=0; ctx=0;}
{
	# Output a [CONTEXT] header whenever 1st col value changes,
		if (ctx!=$1)  {ctx=$1; if (length(ctx) < 1) {print "(no context)"} 
		else {print "[" ctx "]"}}; 
	# and output a project name whenever 2nd  col value [PROJECT] changes,	 
		if (prj!=$2)  {prj=$2; if (length(prj) < 1) {print "\t(Inbox)"} 
		else {
			if ($3==$2) {print "\t• " prj} else {print "\t" prj ":"}
		}};  
	# and output column 3 [TASK] if it differs from col 2
		if ($3!=$2) {print "\t• " $3}
}'

Last edited by RobTrew; 2012-08-10 at 02:57 AM..