How to detect existence of stalled projects?

I want to count the remaining projects that are stalled and set the number to variable nStalled. (The bigger picture: I want to detect stalled projects (i.e., if nStalled > 0 then …), and if any exists, automatically switch to my Stalled Projects perspective.)

I have the following:

set nStalled to count (every project whose ((status is not done) and (status is not dropped)) and (number of available tasks = 0))

but this Applescript counts projects that have tasks that start tomorrow.

How can I accomplish this? While the project class has the properties number of tasks, number of available tasks, and number of completed tasks, there is no property for number of remaining tasks — that would be to obvious and too easy! :-)

I will appreciate any help you all can offer.

Victory is realized! I figured it out.

The problem is that project includes task groups! I had a task group without a subtask, but I don’t care about those. (I figured out that I had one by running @curt’s (Curt Clifton’s) excellent “verify next actions exist” script.) I changed the code above to the following:

        ## Add tasks to stalled projects.
       
        set nStalled to count (every project whose ((status is active) and (number of available tasks = 0)) and (parent task is not missing value))
        if nStalled > 0 then
            my conditions("Stalled")
            return
        end if

and now it works! nStalled properly comes up as 0. The trick was only including “projects” which are (1) active, (2) without available tasks, and (3) have no parent task (i.e., “actual” projects, since empty task groups will always have a parent task value)!


Once again, for context and the benefit of future forum participants, this has to do with a modification I have made in @brandon’s (Brandon Pittman’s) great SmartPerspective applescript, with great input from @ediventurin.

I believe I spoke too soon … still finding bugs, and I think parent task is not what I’m looking for.

Wow. I think I figured it out.

It seems that a custom perspective to search for stalled projects will never show the empty “Miscellaneous” project that OmniFocus automatically creates for you — or, for that matter, any empty single-action list. But my code was counting the empty “Miscellaneous” project as one that was active and had no available tasks (what I consider “stalled”), and therefore was triggering my Stalled perspective (which then showed up empty)!

Once I got on this trail, the solution became evident by looking at @curt’s Verify Next Actions Exist script: you have to exclude single-action lists by only searching for project whose singleton action holder is false. Thus:

		## Add tasks to stalled projects.
		
		set nStalled to count (every project whose status is active and singleton action holder is false and (number of available tasks < 1))
		my notify("nStalled", nStalled)
		if nStalled > 0 then
			my conditions("Stalled")
			return
		end if

Now my script only detects those projects that are truly “stalled” and calls my Stalled perspective when it detects one. Empty single-action lists do not trigger the perspective.

Problem solved!

2 Likes

Nice question. And solution, @apkawel!

Oh, and thanks for mentioning me but, really no need: All credits to @brandon ;)