Intelligent Defer Script

Hi everyone,

I am trying to put together a script that you can put “natural language” dates in like you can in the OF Sidebar (mon+1w for Monday in a week) and use those to defer / due a set of tasks. I try to use transport text for this, but have to clean up (delete) the automatically needed task afterwards.

Any ideas for a more elegant implementation?

tell application "OmniFocus"
    tell content of first document window of front document
	set tasksSelected to value of (selected trees where (class of its value is not item) and (class of its value is not folder))
	if length of tasksSelected is 0 then
		display alert "You didn't select any OmniFocus tasks."
	end if
    end tell
end tell

tell application "OmniFocus"
    tell default document
	set myDeferDate_list to parse tasks into with transport text "no task #mon+1w #" with as single task
	set myDeferDate_task to first item of myDeferDate_list
	set myDeferDate_prop to properties of myDeferDate_task
	set myDeferDate to get defer date of myDeferDate_prop
	delete myDeferDate_task
    end tell
end tell

repeat with otask in tasksSelected
    tell application "OmniFocus"
	set defer date of otask to myDeferDate
    end tell
end repeat

Maybe I’m being dense here, but can’t you already do this? I thought the natural language parsing was already there for defer and due dates.

Hi Joe, I was actually waiting for that question to come up - so - thanks :)

You are correct that the natural language input that OF allows is amongst the best I’ve experienced so far. Putting the dates in directly both in the sidebar as well as in the task list works like a charm.

The problem is that I am using perspectives that do not necessarily show the due / defer dates in the task list & also have the sidebar hidden (minimal ‘Today’ view). I’d still like the option to defer items from that perspective using “mon+1w”-like terminology. That’s why I’m trying to do this via AppleScript.

In AppleScript though, assigning defer / due dates only works with proper dates. My workaround currently is to use transport text to add a new task, assign the defer date of that newly created task back to a variable in AppleScript to then defer the real task by that date. It works, but deleting the temporary task afterwards feels wrong, in a way that if things go sideways I might delete a proper task.