View Single Post
Quote:
Originally Posted by Lizard View Post
The script is available over here.
A few quick thoughts about this very useful script:
  1. It seems to fetch the note data, but doesn't put it into the report. Was that the intention ? (It would certainly speed it up a bit to elide the fetching of note data, which can be quite slow).
  2. Since OF ver 1.8, the introduction of the flattened tasks property has made it possible to write these things rather more easily and briefly (and with noticeably faster execution - see the illustrative sketch below).
  3. The list comes out unsorted. This could be fixed by querying the cache rather than the applescript library, and using an ORDER BY statement in the SQL.

Note also that I have added a clause to exclude completed items from the Next Week list. (More generally, I am a little unclear about the intended role of the modification date conditions in the Last Week list - intuitively I might have expected this to have been defined in terms of the completion date).

Code:
property pstrSubject : "TPS Report"
property pstrGreeting : "Boss Name
"
property pstrThisWeek : "Here's what I did this week:
"
property pstrNextWeek : "Here's what I plan on doing next week:
"

property dteNow : current date
property dteHistory : dteNow - (7 * days)
property dteFuture : dteNow + (7 * days)

tell application "OmniFocus"
	activate
	tell front document
		set refHistory to a reference to (flattened tasks where (in inbox = false and its modification date > dteHistory))
		set refFuture to a reference to (flattened tasks where 
			(in inbox = false) and (completion date is missing value) and (modification date < dteHistory) and (due date > dteHistory) and (due date < dteFuture))
	end tell
	
	set {lstHDate, lstName} to {modification date, name} of refHistory
	repeat with i from 1 to length of lstHDate
		set item i of lstHDate to short date string of item i of lstHDate & space & item i of lstName
	end repeat
	
	set {lstFDate, lstName} to {modification date, name} of refFuture
	repeat with i from 1 to length of lstFDate
		set item i of lstFDate to short date string of item i of lstFDate & space & item i of lstName
	end repeat
end tell

set text item delimiters to return
set strMsg to (pstrGreeting & "
" & pstrThisWeek & "
" & lstHDate as string) & "

" & pstrNextWeek & "
" & lstFDate as string
set text item delimiters to space

tell application "Mail"
	tell (make new outgoing message with properties {visible:true, subject:pstrSubject, content:strMsg})
		make new to recipient at end of to recipients with properties {name:"Boss", address:"the_boss@megacorp.com"}
	end tell
	activate
end tell

Last edited by RobTrew; 2011-02-07 at 02:22 AM..