I am sure this is simple for everyone. I am not a programmer but I have been trying to create a getting things done style app by piecing things together.
The following script will take the “!@” that I put in front of a text and then add it to Omnifocus as a task. this all works. What I can’t get to work is I want to add a tag to the task. the tag will always be the same and in this case, I want it to be “Idea”.
I would be extremely grateful for any help on this.
Here is the script:
// Start every line with a @ to denote it as an idea
const IdeaPrefix = "!@ ";
// Function for removing the task prefix
function removeIdeaPrefix(s) {
var f = (IdeaPrefix),
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(IdeaPrefix)) {
// Remove the trigger from the line
var idea = removeIdeaPrefix(line);
var addTag = idea
var alink = draft.permalink;
console.log(idea);
console.log(greg);
console.log(alink);
// OmniFocus URL Action
doCallbackURL("omnifocus:///add", {"name": idea, "addTag": idea, "note": alink, "autosave": true});
}
}