I see several people have asked for a way to add a link from a created OF task back to some other iOS artifact, but I don’t see any responses.
What I would like to do is create an OF task with a note contains a link back to the Drafts text that created it.
If I create a task in OF myself, adding a URL in the note field, then copy that task to the clipboard, it looks like this:
- A test note for linking from OmniFocus. @parallel(true) @autodone(false)
http://example.com
I can create this exact structure in a Drafts action, using draft.permalink for the URL, etc. When the /paste callback is executed, OmniFocus treats the text as a group, and the URL as a sub task within that group. Any help greatly appreciated.
Ref: Original code
// 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);
task += "@parallel(true) @autodone(false)\n\t";
task += draft.permalink;
console.log(task);
// OmniFocus URL Action
doCallbackURL("omnifocus://x-callback-url/paste", {
"content": task,
"target": "inbox"
});
}
}
Here’s the text sent to the console log by the code above:
A test note for linking from OmniFocus.@parallel(true) @autodone(false)
drafts5://open?uuid=1589AE0F-E0BF-40BA-9944-47BE4D90E348
Event created
Script step completed.
Tags "meetings" assigned.