Questions about the Task.byParsingTransportText function for OmniFocus when using JS plug-ins

I’m trying to embrace the new spirit of Omni Automation, but I’ve run into a real problem in trying to use the Task.byParsingTransportText function when processing emails.

Both Joe Buhlig and Rosemary Orchard have released scripts for processing Inbox tasks that use the Task.byParsingTransportText function. The problem is that after a task is created from using MailDrop and is parsed by the function, the contents of the original email message is dropped from the Notes field. That means that the link back to the original email as well as the content of the email are lost to Omnifocus. It looks like Rose is attempting to restore the original task’s note into the new task note in her script (locate here - https://pastebin.com/rLzNt5sS), but it does not seem to be working.

The behavior of the parse function in OmniJS is not the same as it was in AppleScript. The email link and the contents are preserved in AppleScript.

Does this issue have to be fixed in the function itself (ie: is it a bug?) or is there some JS code that could be applied in a plug-in to add the original Note field contents to the new task that is created by Task.byParsingTransportText function?

Could you post a minimal working example ? I could certainly take a look at the problem.

Just solved this, @bradg. The method .byParsingTransportText of Task class returns an array of Task as noted in the API:

function byParsingTransportText(text: String, singleTask: Boolean or null) 
→ Array of Task

Returns an array of tasks by parsing the transport text formatted input. Optionally, only the first task can be requested (but will still be returned in an array).

Arrays don’t have a .note property. So, you should access one specific element of the array before attempting to change its .note property.

1 Like

Thanks for looking at that. I will tinker with that and let you know how it works.

1 Like

Thank you very much unlocked2412! I am very grateful for your help with this.

I tried this with Joe Buhlig’s Auto-parse OmniFocus JS plug-in (which is located here - https://github.com/joebuhlig/OFScripts/blob/master/Auto-Parser/auto-parser.omnifocusjs). I changed Line 17 of the plug-in by expanding it, as follows:

var TheNote = task.note;
let NewTask = Task.byParsingTransportText(taskName, true);
NewTask[0].note = TheNote;

This ensures that the note field in the task that is being parsed is retained, then placed back into position 0 of the new task array returned from the byParsingTransportText function. I also tried a similar change with Rosemary Orchard’s “Process Inbox Tasks” script and it worked as well. I’m hoping both Joe and Rosemary are able to update their scripts on their various sites and repositories.

So here is my workflow for this:

  1. I have an email I want to transform to a task in OmniFocus. In Apple Mail I select that email.
  2. I click Command-Shift-F to open a mail forwarding window, then address it to my Mail Drop address.
  3. I modify the subject line using the transport text convention of appending it with “- -” and fill-in all of the other transport task info for the rest of the subject line; I am using a textexpander snippet to do that.
  4. I send the email.
  5. When received in the OmniFocus Inbox, I run the revised Auto-Parse plug-in and the task - with the original email text and link back to the Apple Mail retained - is placed in the appropriate project in OmniFocus.

So, none of this is new, but by using Omni Automation it is now universal and I can do this kind of processing on the Mac, iPhone and iPad.

3 Likes

@bradg Thank you so much, it is exactly where I stuck and tried to find or write by myself

Thanks for sharing this. Does this solution still work for you?
I’m not sure what i’m doing wrong but I can’t even get the original script to work at all. I run it, but nothing happens even with the proper syntax in a task.

Can you post the script that doesn’t work for you (including any licensing info) ?