Alternative "Add as To Do to OmniFocus" script

I am experimenting with an early draft of a script which differs from the bundled “Add as To Do to OmniFocus” in four minor respects:

  • The due date can be specified with a variety of relative or absolute expressions, from interval string expressions like today +7d through simple month labels to short absolute date strings.
  • The name of the reminder can be edited.
  • The link(s) in the OmniFocus note text are displayed in human-readable form (DT record names) rather than as raw UUID strings.
  • More than one record can be selected and linked to in the reminder

To install, copy to ~/Library/Scripts/DEVONthink (where ~ is your home folder).
It can then be run from the global scripts menu, or assigned to a keystroke by something like FastScripts or Keyboard Maestro.

(Note that it will not run from Devonthink’s own script menu which displays scripts in folders descending from ~/Library/Application Support/DEVONthink Pro 2/Scripts, and currently seems unable to handle scripts using Applescript’s run script method.)

Not extensively tested, so usual precautions apply: back up your data before experimenting.

If you wish to test it, install to ~/Library/Scripts/DEVONthink (where ~ is your home folder) and launch from the global scripts menu (not Devonthink’s own script menu).
Make OF Reminder of DT (57 KB)

Very nice. :slight_smile:

Thank you for writing this and sharing it.

I’m glad it seem useful.

Draft 004 (above) adds error handling for missing or unparseable dates.

(Missing dates are interpreted as a request for an undated Todo in OmniFocus. The user is alerted to unparseable dates, and invited to edit them).

Thanks for posting this Rob-very promising! I’m not getting the expected results with dates and I’m wondering if it is something on my end or in the script itself. My system is set for the standard US date formats, but if I enter the following in the dialog, here are the results in OmniFocus:

Accept the default ‘today +7d’: Due 12/7/11 @12:00AM in OmniFocus
‘now +7d’: Due 12/7/11 @12:00AM in OmniFocus
‘now +2w’: Due today at 2:00AM in OmniFocus

The scripts were all run ~5:30AM my time, using version 003 and 004 of the script. Suggestions?

Draft 004 is working the dates OK over here, but only adds the OF entry when run from AppleScript Editor.

When run from DTPO’s script menu, the first dialog appears, but not the second - and nothing is added to OF.

I’ve not tried putting the script in the DTPO script menu, but it works fine from the FastScripts menu.

Did date handling change in AppleScript moving from Leopard to Snow Leopard? Could explain why I am seeing different results, although dates with the native DEVONthink>OmniFocus script work fine.

Thanks for those reports. I’ll take a look tonight.

I’m going to speculate that the dates issue is due to differences in the PPC and Intel sides of the universal OmniFocus app. Looking at the script, there is a reference to “Contents:Resources:” & “OF_DateLib.scpt”. Using a PPC, I don’t see this script in the OmniFocus app’s Contents>Resources folder.

OF_DateLib.scpt is in the referenced folder inside the compiled .scptd package that Robin posted, above. That’s why he uses path to me.

Korm - It seems that DT can’t run my date parsing library from its script menu. I had thought this might be because it was a separate script in the resource bundle, but the problem persists even if all the code comes up into the top level script. DT engineers will have a better sense of why, but I think their script launching mechanism may choke on the use of “run script” which I need for the parsing of date strings.

i.e. to use this script, or a derivative thereof, you would either have to launch it with something like a FastScripts or Keyboard Maestro key binding, or drop the parsing of arbitrary dates.

[Though there might be scope for raising this as a DT bug - the script launching code of the OmniFocus toolbar, for example, has no problem with run script in general, or this library in particular, which is taken from my Where in OF script]

Greg Switching my locale and date format to US month/day/year has not sufficed to reproduce the problem which you report. A couple of questions:

  • Which version of OS X are your running ?
  • What happens if you enter a simpler date like “tomorrow” or “1/1/2012” ?

I’m using Leopard 10.5.8 on a PPC. Using both of the examples that you asked about created a properly assigned date.

Got it! I understand just enough AppleScript to get in over my head. I did take a peek at the OF_DateLib.scpt and I’m guessing that the on DateExpression section should not look like this, in plane, black-text typeface?

Well, I guess that the system differences could be a factor - I there were some changes to applescript date processing in Snow Leopard. The thing would be to trace execution through the DateExpression() function, and see where things go adrift. I’m afraid I don’t have a 10.5.8 PPC system to try that with …

In the meanwhile you could also try expressions like:

today + 7 * days
now + 1 * days

(The black string literal which drew your attention in the code is, in fact, correct. Is is assembling an expression to pass to run script)

I now put it in ~/Library/Scripts/DEVONthink and it works just fine from there (the global scripts menu).

Good ! It’s helpful to know that, and I’ve edited the top post to advise installation to the Global scripts folder.

With the latest version I find that any date string other than the default (“today +7d”) is rejected by the parser. E.g., 3/3/11, 03/03/11, 3/3/2011, and so forth, all get rejected.

Thanks for spotting that - I have uploaded ver 0.7 to the start of the thread.

Thanks for the posting, Robin. v007 is working OK from the global scripts menu.

Maybe in 2.0.8, whenever that is, Christian will fix the problem with running custom libraries from the DTPO scripts menu.

Thank you for this great script. I have added it to an upcoming … variant … of the DEVONacademy.

Good, I’m glad it seems useful.

If, however, you have provided a link to version 007, it might be worth using 008 above, which I have just edited to make it compatible with the AppStore-purchased version of OmniFocus.

(OmniGroup have appended the string “.appstore” to the bundle identifier of that version, which will, of course, break a number of existing scripts. My solution is to use the more generic four-character signature code.)

Thus ver 008 uses: application id “OFOC”