Need to count all flagged tasks available

I’m trying to count all available tasks which are shown in my Flagged perspective.
My script seemed to be working fine, until I realised it is not taking into account tasks which are implicitly flagged (show up due to their containers being flagged).

I tried to change my script from this:
set nFlagged to count (every available task of every flattened context whose flagged is true)

… to this:
set nFlagged to count (every available task of every flattened context whose (flagged is true) or (parent task's flagged is true) or (containing project's flagged is true))

Now it works… only IF I don’t have multiple sub levels.

Eg.

  • Project (*)
    • this-task-will-count
    • task-group
      • this-task-won’t-count

Any hints? I’d obviously like the script to count ALL available tasks which are flagged (directly or indirectly) :D

It might be more reliable to

set selected tab to flagged tab

and then count all the items in there?

Ok, but… How can I do that? (count all the items in there)

  • In my attempts even the line suggested results in error :S