Help with script: number of overdue tasks?

Hello! Sorry if this is a very basic topic but I don’t know much about applescript.

Im trying to obtain the number of overdue tasks with applescript with this:

tell application "OmniFocus"
tell front document
	-- Get the list of tasks
	set thePastTasks1 to every flattened task where its completed = false and due date is less than (current date)
	set PastCount1 to count of thePastTasks1
	if thePastTasks1 is not equal to {} then
		set reportText1 to " ☹︎ Past: " & PastCount1
		return reportText1
	end if
end tell -- end tell front document
end tell -- end tell application "OmniFocus"

But no matter what I try I never obtain the same value of overdue that the iOS app shows in the “Badges Menu”

Can someone tell me what am I doing wrong?

Thanks in advance!

I suspect you are running into the same challenge I have. What I’ve found is that in your script, the value of thePastTasks1 will not include tasks where the due date is on the project or a parent task. It only appears to include tasks where the due date is on the task itself. Take a closer look at which tasks are missing from the list you see vs. what is reported on the Forecast view of the app.

I haven’t figured out a good way to mimic the list of tasks that are reported in the Forecast view inside the app via a script.