What's AppleScript for "defer til next Monday?"

How does one set a task’s defer date to “next Monday” via AppleScript? (i.e. get the same results as if one typed “mon” into the defer date box in the OF2 application itself).

I’ve been getting by with tweaking existing Omnifocus scripts, but can’t figure out how to manage this one.

Thanks for any help!

Mike

1 Like

I have not tried it, but I thought you could just put “next monday” in as the defer date from your script and the date parser would handle it internally?

Here’s a way to calculate next monday in AppleScript:

set today to current date
set daysTillMonday to (7 - ((weekday of today as number) - 2)) mod 7
set nextMonday to today + days * daysTillMonday

Hope this helps!

3 Likes

Thanks Svenl! That did the trick.

A followup question - if a function returns your nextMonday value, can that be used to see if an action’s due date is already next Monday? i.e. can we ask

if defer date of _action is equal to the_result_of_sevel’s_function()

I could not read back the value when I just tried, but I am not that experienced with applescript. Maybe someone else can get it to work. I was wondering if after changing the defer date you could select the Omnifocus task at the top of the list. I have a several little scripts to defer items but one I run one of these scripts to defer the time, I would like the top item on the list to be selected (I commonly do this to items in the defer perspective. Is there any way to do this?