For many years I am using a script to add a draft line starting with @ as a task to OmniFocus. I now want to use the drafts tag as Project in OmniFocus. I cannot get it working. Can somebody help me? Very appreciated. Below the script I am using:
// Start every line with a @ to denote it as a task
const taskPrefix = "@";
// Function for removing the task prefix
function removeTaskPrefix(s) {
var f = (taskPrefix),
r = "",
re = new RegExp(f,"g"),
matches = s.match(re);
if (matches) {
return s.replace(re,r);
}
}
// Function to perform the callback url
function doCallbackURL(url, params) {
var cb = CallbackURL.create();
cb.baseURL = url;
for(var key in params) {
cb.addParameter(key, params[key]);
}
var success = cb.open();
if (success) {
console.log("Event created");
} else {
console.log(cb.status);
if (cb.status == "cancel") {
context.cancel();
} else {
context.fail();
}
}
}
// Scan for the task prefix in the draft
var lines = draft.content.split("\n");
for (var line of lines) {
// If the line includes the task prefix,
// we remove exclude it from the final notes
if (line.startsWith(taskPrefix)) {
// Remove the trigger from the line
var task = removeTaskPrefix(line);
var alink = draft.permalink;
console.log(task);
console.log(alink);
// OmniFocus URL Action
doCallbackURL("omnifocus:///add", {"name": task, "project": draft.tags[0], "note":"Title and link to note: " + draft.displayTitle + ": with link: " + alink, "autosave": true});
}
}