Set the defer date to the current due date?

Hello,

I’m trying to automate setting the defer date to the current due date, and then setting the due date to the current due date + 4 hours, however I’ve no idea where to begin. I’ve looked at the Omnifocus dictionary in Script Editor and I can see that there is both a defer date and a due date entry, etc., but it doesn’t actually help me all that much :(

If someone could point me in the right direction (or more!), then I would be very appreciative.

Try this with a selection of tasks

on run

set now to (current date)
set currentTime to time of (current date)
set nowDate to now - currentTime
set theAdvanceDate to nowDate + (4 * days)

tell application "OmniFocus"
	
	tell content of front document window of default document to ¬
		set theSelectionList to the value of every selected tree
	if the (count of items in theSelectionList) is 0 then return
	tell front document
		repeat with theItem in theSelectionList
			set theNewDefer to the due date of theItem
			if theNewDefer is missing value then
				set theNewDefer to theAdvanceDate
			end if
			set theNewDue to (theNewDefer + (4 * days))
			set the due date of theItem to theNewDue
			set the defer date of theItem to theNewDefer
		end repeat
	end tell
end tell

end run


JJW

2 Likes

Thank you so much for this! I just tried it out and it actually sets the due date to be 4 days into the future not hours, but that was easy to go through and fix. I’ll be using this as a spring board for many projects :)

Oh, yes! You did say hours not days. I was wrapping my head around moving the dates and lost that important note.

I suspect with some clever coding the times could be shifted by 4 hours ahead to the nearest whole number increment of hours, i.e. 11:00 am rather than 11:13:25 am. I would leave that to someone more particular than me to code.

Glad that this was of help in any case.


JJW

1 Like