this following script is from an imported Action that:
- finds all "- " lines in the draft and sends each task to Things3 Inbox - ✓great
- collects - tasks together as list & appends them @ bottom of draft - ✓ great
- DELETES the - lines from the original location in the draft -
This is an awesome action for collecting action points from a document, but I’d like to leave the tasks in location as they are in the original draft.
Which lines need editing or deleting?
my script skills are null but I’m sure this is “Hello world” to someone…
thanks
S.
Action script code pasted:
// check to see if draft is blank
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;
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();
}
}