How to set defer and due to specific values?

Hi!

I am worthless with any and all scripting languages, but my goal is to have a set of scripts that allows me to set the defer and due dates for one or more actions to certain times I use most often.

Defer until 8am, 1pm, 9pm (today or tomorrow)
Due 1pm, 6pm, 10pm (today or tomorrow)

If there’s already a defer or due date, I’d like to overwrite it, not modify it.

I’ve tried to kludge my way through it with some scripts I found but no luck so far. Ultimately I’ll wind up pairing this with Keyboard Maestro to assign hotkeys to these tasks.

Thanks for any help or direction you can give me!

1 Like

There is a script from C-Command Software that defers a task to tomorrow, and if you change ”+ 1” at the end of the script to other values, it will defer tasks to other days instead. Below the line for defer date, there is a line for setting the time (which I haven’t tried myself, as I’m happy with simply setting the days). You could probably also alter the script to set due dates instead of defer dates.

Defer to tomorrow

1 Like

I’ve been messing with that one, but the problem I’m having there is that activating that script repeatedly just increments the defer date by +x days and +y hours. I want one that is a static “tomorrow 8am” etc., every time I run the script.

I am certainly not good at scripting either, but the script works for me with dates only. After having had a hard time understanding how to specify time in Applescript (might have been a system language problem) I got the same problem as you described when time is included. I think I have found a solution for you, though. When I deleted the part ”+ (time of _oldDate)” from the script, it worked for me the way you wanted, with time specified.

1 Like

Ah ha! You’ve put me on to it. Thank you.

These changes do what I want, and I can change the times as desired.

on calculateDate(_oldDate)
	if _oldDate is missing value then
		return my midnightTomorrow()
	else
		return (my midnightTomorrow())
	end if
end calculateDate

on midnightTomorrow()
	set _date to (current date)
	set day of _date to (_date's day) + 1
	set time of _date to 28800
	return _date
end midnightTomorrow

Glad to hear that! I might find it useful myself to defer by time – now that I’m aware that I have to specify the time in the script in multiples of seconds.

I like to set a few tasks (no more than three) to accomplish while at work, or something specific I need to do when I get home. Now I can quickly choose those tasks with a hotkey and see them easily in the forecast view.

For completion’s sake, here’s what I wound up with:

defer until 8am, due 2pm:

on run {}
	repeat with _action in my selectedActions()
		my processAction(_action)
	end repeat
end run

on selectedActions()
	tell application "OmniFocus"
		return my filterValues(my selectedValues(), {inbox task, task, available task, remaining task})
	end tell
end selectedActions

on selectedValues()
	tell application "OmniFocus"
		return value of selected trees of content of first document window of front document
	end tell
end selectedValues

on filterValues(_values, _classes)
	tell application "OmniFocus"
		set _result to {}
		repeat with _value in _values
			if _classes contains _value's class then
				copy _value to end of _result
			end if
		end repeat
		return _result
	end tell
end filterValues

on processAction(_action)
	tell application "OmniFocus"
		set _action's defer date to my calculateDeferDate(_action's defer date)
		set _action's due date to my calculateDueDate(_action's due date)
	end tell
end processAction

on calculateDeferDate(_oldDate)
	if _oldDate is missing value then
		return my deferDateTime()
	else
		return (my deferDateTime())
	end if
end calculateDeferDate

on calculateDueDate(_oldDate)
	if _oldDate is missing value then
		return my dueDateTime()
	else
		return (my dueDateTime())
	end if
end calculateDueDate

on deferDateTime()
	set _date to (current date)
	set day of _date to (_date's day)
	set time of _date to (8 * 3600)
	return _date
end deferDateTime

on dueDateTime()
	set _date to (current date)
	set day of _date to (_date's day)
	set time of _date to (14 * 3600)
	return _date
end dueDateTime

and for “tomorrow” instead of “today,” make these changes:

   on deferDateTime()
    	set _date to (current date)
    	set day of _date to (_date's day) + 1
    	set time of _date to (8 * 3600)
    	return _date
    end deferDateTime

    on dueDateTime()
    	set _date to (current date)
    	set day of _date to (_date's day) + 1
    	set time of _date to (14 * 3600)
    	return _date
    end dueDateTime

It’s all borrowed from that link above, and sloppily modified, but it suits my purpose.