Incremental Due Date Automation


#1

I regularly divide up my projects into smaller sub-projects and assign incremental due dates to them {e.g., Read page 1-25 (due today), Read page 26-80 (due tomorrow), read page 81-104 (due +2days) etc.}
But when you’ve got a sub-project of 20+ items, assigning incremental days becomes an exercise in tedium.

Does anyone know of an AppleScript that could assign due incremental due dates to a list of projects?

So, if you run the script, it will automatically assign due date (today) to the first task, (tomorrow) to the second, (today +2) to the third, (today +3) to the fourth… ad infinitum.


#2

Not sure if this is exactly what you need, but I have an AppleScript that does it specifically for reading a book. There’s a Siri Shortcut for it as well.


#3

This is outstanding, thanks Joe! I can tweak this to be precisely what I’m looking to accomplish. Very much obliged!


#4

Joe, just wondering… is it easy to tweak the script to prompt me for the starting pages? I don’t always want to begin with page 1. Sometimes I need to read a section of text that begins on pg 42 (which in this particular instance, is not the answer to everything after all. Just wondering…


#5

also… is there a way to set the due dates equivalent to the defer dates? I like viewing these deadlines in my forecast view. thanks again.


#6

Line 33. You could add a dialog to ask where to start.

Line 44. You can assign the due date to the deferDate variable.


#7

Joe, you’re a gentleman and a scholar. Thanks for your help. My coding skills are on a par with my golf skills. both are actually quite terrible.

Here’s the line that I added to prompt me for the starting pages:
set startPage to text returned of ( display dialog “Starting Page?” default answer “1”)
It’s not quite yielding the desired results. This might have something to do with the fact that I have never done this before. Any advice would be enormously helpful.

thanks,
the guy with the dunce cap.


#8

Can you share the whole script as you have it? That would make it a lot easier.


#9

Absolutely: here it is:

set myTag to “Reading”

set dateFormat to “mmddyyyy” – choose “mmddyyyy” or “ddmmyyyy” based on your region

set bookTitle to text returned of ( display dialog “What’s the title of the book?” default answer “”)

set numPages to text returned of ( display dialog “How many pages are in the book?” default answer 0) as integer

set startDate to text returned of ( display dialog “When should this start?” default answer “yyyymmdd”)

set endDate to text returned of ( display dialog “When should this end?” default answer “yyyymmdd”)

set deferYear to text 1 thru 4 of startDate

set deferMonth to text 5 thru 6 of startDate

set deferDay to text 7 thru 8 of startDate

set endYear to text 1 thru 4 of endDate

set endMonth to text 5 thru 6 of endDate

set endDay to text 7 thru 8 of endDate

if (dateFormat = “mmddyyyy”) then

set endDateString to endMonth & “/” & endDay & “/” & endYear

set endDate to date endDateString

set dateString to deferMonth & “/” & deferDay & “/” & deferYear

set deferDate to date dateString

else if (dateFormat = “ddmmyyyy”) then

set endDateString to endDay & “/” & endMonth & “/” & endYear

set endDate to date endDateString

set dateString to deferDay & “/” & deferMonth & “/” & deferYear

set deferDate to date dateString

end if

set numDays to ((endDate - deferDate) div days) + 1

tell application “OmniFocus”

tell document of front window

set pagesPer to numPages / numDays

set startPage to text returned of ( display dialog “Starting Page?” default answer “1”)

set endPage to pagesPer as integer

set i to 2

set taskTitle to "Read pages " & startPage & " - " & endPage & " of " & bookTitle

set theTag to first flattened tag where its name is myTag

set newTask to make new inbox task with properties {name:taskTitle, defer date:deferDate, primary tag:theTag}

repeat (numDays - 1) times

set startPage to endPage + 1

set endPage to round (pagesPer * i) rounding up

set taskTitle to "Read pages " & startPage & " - " & endPage & " of " & bookTitle

set deferDate to deferDate + (60 * 60 * 24)

set newTask to make new inbox task with properties {name:taskTitle, defer date:deferDate, primary tag:theTag}

set i to i + 1

end repeat

return bookTitle & ": " & numPages

end tell

end tell

thanks a million for even looking at this!


#10

Give this a try:

set myTag to "Reading"

set dateFormat to "mmddyyyy" -- choose "mmddyyyy" or "ddmmyyyy" based on your region

set bookTitle to text returned of (display dialog "What’s the title of the book?" default answer "")

set totalPages to text returned of (display dialog "How many pages are in the book?" default answer 0) as integer

set firstPage to text returned of (display dialog "Starting Page?" default answer "1") as integer

set numPages to (totalPages as integer) - (firstPage as integer)

set startDate to text returned of (display dialog "When should this start?" default answer "yyyymmdd")

set endDate to text returned of (display dialog "When should this end?" default answer "yyyymmdd")

set deferYear to text 1 thru 4 of startDate

set deferMonth to text 5 thru 6 of startDate

set deferDay to text 7 thru 8 of startDate

set endYear to text 1 thru 4 of endDate

set endMonth to text 5 thru 6 of endDate

set endDay to text 7 thru 8 of endDate

if (dateFormat = "mmddyyyy") then
	
	set endDateString to endMonth & "/" & endDay & "/" & endYear
	
	set endDate to date endDateString
	
	set dateString to deferMonth & "/" & deferDay & "/" & deferYear
	
	set deferDate to date dateString
	
else if (dateFormat = "ddmmyyyy") then
	
	set endDateString to endDay & "/" & endMonth & "/" & endYear
	
	set endDate to date endDateString
	
	set dateString to deferDay & "/" & deferMonth & "/" & deferYear
	
	set deferDate to date dateString
	
end if

set numDays to ((endDate - deferDate) div days) + 1

tell application "OmniFocus"
	
	tell document of front window
		
		set pagesPer to numPages / numDays
		
		set endPage to (firstPage + pagesPer) as integer
		
		set i to 2
		
		set taskTitle to "Read pages " & firstPage & " - " & endPage & " of " & bookTitle
		
		set theTag to first flattened tag where its name is myTag
		
		set newTask to make new inbox task with properties {name:taskTitle, defer date:deferDate, primary tag:theTag}
		
		repeat (numDays - 1) times
			
			set startPage to endPage + 1
			
			set endPage to round (firstPage + (pagesPer * i)) rounding up
			
			set taskTitle to "Read pages " & startPage & " - " & endPage & " of " & bookTitle
			
			set deferDate to deferDate + (60 * 60 * 24)
			
			set newTask to make new inbox task with properties {name:taskTitle, defer date:deferDate, primary tag:theTag}
			
			set i to i + 1
			
		end repeat
		
		return bookTitle & ": " & totalPages
		
	end tell
	
end tell

#11

This is perfect! Joe, I’m indebted to you. Thanks very much!


#12

I just tried running the script and it seems to work except it seems to work the page numbers backward instead of forward.
Thus, if you start at pg 485, it works backwards and ends up at pg 154.
Any idea why that would be?


#13

Can you give me the inputs you provide the script that cause the error so I can run it on my end?


#14

sure:
Title: Soteriology
How many pages: 174
Starting page: 475
Start date: 20190905
End date: 20190924


#15

Try switching these two. 😉


#16

haha! I realize what it looks like, but actually I"m trying to read 174 pages, from pg 475 – pg 649.


#17

Try this:

How many pages: 649
Starting page: 475

😉


#18

oh wow. I was being really obtuse. The lights just went on. Thanks Joe!