I am using the script below to take a line in Draft that starts with a - and sending it to OmniFocus as a new task with the correct tag. This works really well. What I would like to add is the ability to have the script put information into the βNoteβ section of the OmniFocus task.
For example,
If I write this in Drafts:
Work with people to finish this project | I need to connect with Fred so he knows what to do.
After the right script was created, in OmniFocus it would look like this:
Task - Work with people to finish this project
Tag - Fred
Note - I need to connect with Fred so he knows what to do.
In the text from Drafts Iβm using the β|β as the divider between the title of the Task and what should go into the Note. I am not married to this so if there is a better way to do this Iβm open to it.
Thank you!!!
// Add - Fred - *
function processDraft(p_strIdentifier, p_strNewPrefix = "")
{
// Check each line of the current draft
for (let strLine of draft.lines)
{
// If the line starts with the task prefix, process it
if (strLine.startsWith(p_strIdentifier))
{
// Build and call the URL
let cb = CallbackURL.create();
cb.baseURL = "omnifocus:///add";
cb.addParameter("name", p_strNewPrefix + strLine.substring(p_strIdentifier.length));
cb.addParameter("note", draft.permalink);
cb.addParameter("project", draft.displayTitle);
cb.addParameter("context", "π - Fred");
cb.addParameter("autosave", "true");
cb.open();
}
}
return;
}
//Call the function to process the draft with the identifier and the optional prefix to use in OmniFocus.
processDraft("-", "π ");
you need several things to achieve what you need. Iβm not a very experienced javascript user so there might be a more efficient / elegant solution for your problem.
Here is what I would do (attention i just edited tthis online and did not test it so there may be some typos or syntax issues.:
const taskNoteDivider = "|";
// Add - Fred - *
function processDraft(p_strIdentifier, p_strNewPrefix = "")
{
// Check each line of the current draft
for (let strLine of draft.lines)
{
// If the line starts with the task prefix, process it
if (strLine.startsWith(p_strIdentifier))
{
// check if the divider is included in the task
let taskName = "";
let taskNote = "";
if(strLine.includes(taskNoteDivider){
// split the line into the task name and the content for the note
let lineContent = p_strNewPrefix + strLine.substring(p_strIdentifier.length);
let lineParts = lineContent.split(taskNoteDivider);
taskName = lineParts[0];
taskNote = linePart[1] + "\n" + draft.permalink;
} else {
taskName = p_strNewPrefix + strLine.substring(p_strIdentifier.length);
taskNote = draft.permalink;
}
// Build and call the URL
let cb = CallbackURL.create();
cb.baseURL = "omnifocus:///add";
cb.addParameter("name", taskName);
cb.addParameter("note", taskNote);
cb.addParameter("project", draft.displayTitle);
cb.addParameter("context", "π - Fred");
cb.addParameter("autosave", "true");
cb.open();
}
}
return;
}
//Call the function to process the draft with the identifier and the optional prefix to use in OmniFocus.
processDraft("-", "π ");
I want to thank you for taking the time to help. I really appreciate it. I am having a problem with the syntex. I keep getting the attached error. Any chance you can help me out with it (again?)?
I see one of these variable references seems to be missing an βsβ from the end of the name. The let defines the variable, so that is the name that should be used throughout. Typo in the name simply refers to a different variable that may or may not exist.