Script for OF to retrieve tasks completed and created within specified date range

As part of my daily/weekly/monthly review, I’m manually copying tasks from perspectives in Omnifocus in taskpaper format and summarizing them with AI.

There are times when I’m away from my computer for multiple days, making my perspectives less useful due to the lack of relative time periods (today, yesterday, within the last week, within the last month).

I know it’s possible to pull down more than I need and filter out the tasks that don’t align with the date range I’m interested in but I’d prefer a method where I can programatically retrieve tasks based on date range criteria.

I’m open to any and all possibilities, whether via shortcuts or a scripting language.

Any creative ideas are greatly appreciated.

Thanks in advance,
Ryan

Do you want to export completed task within specified date range to TaskPaper or directly querying AI using your completed tasks from the specified date range directly inside OmniFocus ?

I’m open to either, as long as I get more context than task title (tags and project being the most important), taskpaper format isn’t required but I’ve been copying as taskpaper to ensure I get additional context that doesn’t come with a regular copy.

But you do get tags in a regular taskpaper export, right ? What context do you need aside from those pieces of information ?

So, the end goal is AI processing and not TaskPaper format ?

yes, end goal is AI processing, the context included in the stock “copy as taskpaper” is sufficient.

I understand. So, fortunately you have two classes defined in OmniFocus API:

Omni Automation supports calls to network resources that require authentication or use a RESTful API (Representational State Transfer).

There are two shared classes for enabling network retrieval and setting of data using the fetch() function of the URL class:

  • URL.FetchRequest
  • URL.FetchResponse

Using those classes, you can call an AI API and receive results inside OmniFocus OmniAutomation API.

With Shortcuts, you can use Get contents of URL action to call the API and process that result.