Detect whether a task is available

I’m programming OmniFocus in Objective-C using the Scripting Bridge. I’d like to know two things:

  1. How do I query all available tasks? This could be by filtering the document’s flattenedTasks with a predicate, but I don’t know what predicate to use.
  2. For any given task (i.e. I already have a Task object), how can I tell whether it is available? Do I have to do the logic (check for defer date, context on hold, project on hold etc) myself?

Hearing how you do those things in pure AppleScript may be helpful, so any AppleScript gurus are also welcome to reply!


Some AppleScript info that hopefully you can translate into Objective-C.

  1. In AppleScript, to find the contexts which are inside the Errands context, you could have a line like

    set errandContext to context named “Errands”
    set errandChildren to every flattened context whose container is errandContext

  2. You can get, for example,
    every available task of every flattened project

and then look within those tasks for the one you want, but I don’t see a way to ask a given task whether it is available.

Any idea how to combine every available task of every flattened project with a flagged status?

(Basically I want to clear the flagged state of every available task, clearing my “today” list)

Ended up with this:

-- Unflag every available task in every context (it has to be assigned a context)
tell application "OmniFocus"
	tell default document
		set flagged of (every available task of every flattened context whose flagged is true) to false
	end tell
end tell

Does this actually work? I’m getting an AppleScript error. I can do this for every flattened context, but that’s no use if I want to get the tasks that have no context.

Arg! You’re right. It won’t work. According to the AppleScript dictionary, Contexts can have Available Tasks, but Projects don’t. I’ll create a feature request in our bug system to see if we can bring this over to projects.

Without access to the ‘available tasks’, you’d have to do the availability logic yourself, which seems rather like re-inventing the wheel. I’ll make sure that feature request is filed too.

Could we have “available” as a property on Task? Then we could say something like “all tasks of default document whose available is true”…

Yes, that’s what I meant by “I’ll make sure that feature request is filed too.” And it is filed now!

1 Like