The Omni Group Forums

The Omni Group Forums (
-   OmniFocus Extras (
-   -   Custom text exports from OmniFocus (applescript-based query language) (

RobTrew 2011-01-14 06:08 AM

Custom text exports from OmniFocus (applescript-based query language)
A general script (to be run from the OS X Terminal command line with osascript), which generates custom lists of records from the OmniFocus database. (Standard output text, which can be redirected to text files, or piped through further Terminal commands).

Differs from earlier scripts in that the fields to be exported can be specified in a SELECT list.

(Note that its function is essentially the same as [URL=""]the script[/URL] on which the set of Geektool scripts in another thread are based (and this could also be used, of course for Geektool).

The key difference is that the other script uses SQL to query the OF cache, whereas this script restricts itself to Applescript and the OF Applescript library.

Each approach has its profile of cost and benefit.

[I]Vanilla Applescript:[/I][INDENT][B]+[/B]
The syntax is more user-friendly, and the approach is more durable. The Applescript library is likely to remain fairly stable across OF builds. Officially supported.
A bit slower, and only works when the OmniFocus application is running. Some blind patches in its access to information. Sorting not directly supported.[/INDENT][I]SQL + Cache[/I] : [INDENT][B]+[/B]
Rather fast, and works even when OmniFocus is not running. Allows reading of some data fields which are not accessible through the Applescript library. Lists can be quickly and simply sorted by any field.
The syntax is more opaque, and the approach is less durable. Scripts using this approach will need to be updated whenever a new build of OmniFocus changes the schema of the cache. An OmniGroup comment: "at the deep end of not officially supported" :-)[/INDENT]
(In short if the Geektool lists of OF actions on your desktop are broken by a future build of OF, you can use this script until [URL=""]OFGeekTool.scpt[/URL] is updated. It will work, though only when OF is running. It will also be slower, and will tie up your processor more, so you would probably need to reduce the refresh interval.)

[B]NAME[/B][INDENT]OF-AQL OmniFocus for Mac Applescript-syntax Query Language[/INDENT][B]SYNOPSIS[/B][INDENT]Run from the OS X terminal:

osascript ~/Library/Scripts/Applications/Omnifocus/OF-AQL.scpt -?
osascript ~/Library/Scripts/Applications/Omnifocus/OF-AQL.scpt --help
osascript ~/Library/Scripts/Applications/Omnifocus/OF-AQL.scpt query [header]

[query]: (single-quoted argument on the command-line)
[INDENT][I]SELECT field1, field2, fieldn FROM tasks|projects|folders|contexts [WHERE condition(s)][/I][/INDENT]
[header]: (single-quoted argument on the command-line)
[INDENT]Any single-quoted descriptive string. Defaults to an upper-case version of the query. Suppress by specifiying an empty string.[/INDENT][/INDENT][B]DESCRIPTION[/B][INDENT]OF-AQL.scpt is a draft Applescript which generates custom lists, in text format, of tasks, projects, folders, or contexts in the default OmniFocus database. The list description language is essentially that of the OmniFocus Applescript library. The [URL=""]Where in OF[/URL] script can be used to explore this language interactively.

[I]EXAMPLES[/I] (OS X terminal command lines):
[INDENT][I]osascript ~/Library/Scripts/Applications/Omnifocus/OF-AQL.scpt 'select [B]name[/B], [B]due date[/B] from tasks where next is true' 'Next Action' > NextAction.txt

osascript ~/Library/Scripts/Applications/Omnifocus/OF-AQL.scpt 'select [B]folder[/B], [B]name[/B], [B]due date[/B] from projects where completed is false and status=active' 'Active Projects'

osascript ~/Library/Scripts/Applications/Omnifocus/OF-AQL.scpt 'select [B]folder[/B], [B]project[/B], [B]name[/B] from tasks where completed=false and name of its context="Phone"' 'Phone:' > Phone.txt
[INDENT]From [URL=""][/URL]

Unzip and copy to your OmniFocus script folder, so that it has the path:


All times are GMT -8. The time now is 09:16 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2022, vBulletin Solutions, Inc.