I’m starting to manage project reference materials in Drafts and I created an action that sends the current line to Things as a task. Works great. However, I’d like to take it one step further.
My project reference material looks like this:
# Project
- item 1
- item 2
> additional notes and links and things
> perhaps even multiple blocks of notes
- item three
> sometimes just one block of notes
Could I edit my existing script (pasted below), so that before sending the current line to Things as a task, it checked to see if there were any note blocks below (which will always be preceded by a tab and a “>”, then sent those along too as “notes”?
let [loc, len] = editor.getSelectedLineRange(),
str = editor.getTextInRange(loc, len),
icon = '🔘',
listTitle = draft.processTemplate("[[title]]"),
regex = /# /,
regex2 = /- /;
let todoList = listTitle.replace(regex,"");
let todoTitle = str.trim();
todoTitle = todoTitle.replace(regex2,"");
var cb = CallbackURL.create();
const baseURL = "things:///add?"
cb.baseURL = baseURL;
cb.addParameter("title",todoTitle);
cb.addParameter("notes",draft.permalink);
cb.addParameter("list",todoList);
cb.waitForResponse = true;
var success = cb.open();
if (success) {
console.log("Task created in Things" + cb.url);
var response = cb.callbackResponse;
}
else {
context.fail();
}
newStr = icon + ' ' + todoTitle + " [things](things:///show?id=" + response["x-things-id"] + ")\n";
editor.setTextInRange(loc, len, newStr);
// move the cursor to the end of the edited line
editor.setSelectedRange(loc + newStr.trim().length, 0);
editor.setSelectedText('');
// activate is not required if the action is launched via a keyboard button
editor.activate();