View Single Post
A shell script version of Due Soon, illustrating an approach to listing imminently due tasks with their due date (+time) and number of remaining days, in NerdTool GeekTool etc

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
echo "DUE SOON:"
OFQUERY="sqlite3 $HOME/Library/Caches/$OFOC/OmniFocusDatabase2"
YEARZERO=$($OFQUERY "SELECT strftime('%s','2001-01-01')")
NOW=$($OFQUERY "SELECT (strftime('%s','now', 'localtime'))")
DUE="($YEARZERO + tt.effectiveDateDue)"
DAY=86400
DAYS_LEFT="round((($DUE-$NOW)*1.0)/$DAY,1)"
DAYS_OVERDUE="($NOW-$DUE)/$DAY"

$OFQUERY "
SELECT f.name, p.name, c.name, tt.name, $DAYS_LEFT, strftime('%m-%d %H:%M',$DUE, 'unixepoch') 
FROM (((task t left join projectinfo pi on t.containingprojectinfo=pi.pk) tt 
left join task p on tt.task=p.persistentIdentifier) 
left join context c on tt.context = c.persistentIdentifier) 
left join folder f on tt.folder=f.persistentIdentifier
WHERE tt.isDueSoon=1 and $DAYS_OVERDUE < 14
" | awk '
BEGIN {FS="\|"; fld=0; prj=0; ctx=0;}
{
	# Whenever the value of col. 1 changes, write it out as a FOLDER header,
	if ( fld!=$1)  { fld=$1; if (length( fld) < 1) {print "\n(No folder)"} 
	else {print "\n[Folder: " toupper( fld) "]"}};
		
	# and whenever the value of col. 2 changes, write it out as a PROJECT header.
	if (prj!=$2)  {prj=$2; if (length(prj) < 1) {print "\n\t(INBOX)"} 
	else {print "\n\t" toupper(prj)}};
	
	# Whenever the value of col. 3 changes, write it out as a [CONTEXT] sub-header.
	if (ctx!=$3)  {ctx=$3; if (length(ctx) > 0) {print "\t[" ctx "]"}};
		
	# and whenever col 4. contains sth other than the project name, write it out as a • TASK.
	if (length($4) > 0 && $4!=$2) {print "\t• " $4, "("$5" days to "$6")"}
}'

Last edited by RobTrew; 2012-08-05 at 07:39 PM..