Converting an Omnifocus Taskpaper Markdown Draft to work for Things 3

Hi Drafts community,

I’m a bit stuck and I was wondering whether anyone here could offer some assistance.
I used to use Omnifocus and am now slowly transitioning back to Things3 but I have a draft that I use quite often which I managed to get working for Omnifocus but I have no idea how to do it for Things3.

I would be incredibly grateful if anyone has any input for how to adapt it for Things3 compatibility.

It is written in javascript and basically parses my meeting notes template in drafts and picks out all markdown tasks and then copies them into Omnifocus (I think in taskpaper format) so in the following document it would pull out Task 1 and add the tag “Meeting Action” to it:

# Meeting Notes

## Actions
- [ ] Task 1

## Content
Bla bla bla 

So essentially if anyone knows a quick fix for adapting it or would be willing to help me out real quick I would be infinitely grateful. I don’t really know javascript too well but if anyone can help me out I’m willing to tip for your time as this is really invaluable to my workflow.

This is the current code I’m using and a screenshot of my usage:

let taskpaper = '';
draft.content.split("\n").forEach(function(line){
	if (line.startsWith('- [ ]')) {
		taskpaper += "Meeting Task: " + line.replace('[ ]', '') + " @tags(Meeting Action 🎙)\n";
	}
});

const baseURL = "omnifocus://x-callback-url/paste";
let cb = CallbackURL.create();
cb.baseURL = baseURL;
cb.addParameter("content", taskpaper.trim());
cb.open();

Hi Nicolo,

It shouldn’t be too hard to adapt your action for use with Things.

You’ll want to look at the TJSContainer object in the Drafts scripting guide. (TJS stands for Things Javascript).

Us a TJS container to build up your tasks instead of the callback URL in your current script and you should be golden.

1 Like

Hi Cpac,

That actually looks really good! I’ll give this a go when I get home, I’m not great at javascript but this seems pretty straight forward :blush:

Thanks so much!

For reference, I ended up using the following code to achieve my goals and it worked perfectly :slight_smile:

var content = editor.getText();
var check = content.length;
var taskList = "";

if (content.length == 0) {
alert("Draft is blank");
context.cancel("Draft was blank");
}

// Call API for each line in a draft
// split draft and loop over lines
var lines = content.split("\n");

var thingsTask = Array();

for (var line of lines) {
if (line.startsWith("- [ ]")) {
task = line.replace("- [ ]", "").trim();
temp = TJSTodo.create();
temp.title = task;
temp.tags = ["Meeting Action 🎙"];
thingsTask.push(temp);
taskList += task + "\n";
//content = content.replace(line + "\n", "");
}
}

if (thingsTask.length) {
var container = TJSContainer.create(thingsTask);
var cb = CallbackURL.create();
cb.baseURL = container.url;
var success = cb.open();
if (success) {
console.log("Tasks created in Things");
content = content + "\n\nTasks collected:\n" + taskList;
editor.setText(content);
} else {
context.fail();
}
}
1 Like