I have a script to launch perspectives based on certain conditions. At certain point I have the following line, to count available tasks:
if (count (every available task of every flattened context)) > 0 then
I’d’like to exclude from that count all Errands (context) tasks.
I’d count all tasks, count all tasks in the Errands context, and subtract.
Don’t know how to do that… :(
Could you help?
tell application "OmniFocus"
set theDoc to default document
set allAvailable to count (every available task of every flattened context)
set errandsAvailable to count (every available task of context named "errands")
set actualAvailable to allAvailable - errandsAvailable
@lizard thanks! It works brilliantly. Any chance you can show me how to change it so it takes into account “Errands” and all its sub contexts? :D
If that isn’t feasible, counting all tasks under a folder would do it for me too.
If you don’t have more than two layers of contexts (in other words, Errands > Grocery, but not Errands > Grocery > Circle K), then you could find all the other contexts whose stuff you need to count with
set errandContext to context named "Errands"
set errandChildren to every flattened context whose container is errandContext
You’re actually making the same assumption with your folder solution. It won’t find a project that’s inside a folder that’s inside of “FolderName”
In fact, I have this one extra level of contexts (Errand > Groceries > Circle K). Only way then would be iterating over Errands and its sub-contexts? Not familiar with that. Trying to find a way.
For now, I’ve set with the Folder based solution (no sub Folders there), but the solution would be much more elegant, and flexible, if I managed to find a(n efficient) way to count the Errands (context) tasks.