I’m trying to update my Send Tasks to OmniFocus action to insert the permalink into the note of any wiki-linked lines.
This is my Frankenstein script that I cobbled together from pieces of my original script, Rosemary’s send to OmniFocus, and Greg’s “insert draft in place of wiki-links” script… It was working in an earlier version but now is failing at line 10…
I’ve tried everything I can think of but I can’t figure out why. Any ideas?
const note_re = /\|/;
const wiki_re = /\[\[(.+?)\]\]\s/gm;
let findLinkedDraft = (title) => {
let found = Draft.queryByTitle(title);
if (found.length == 0) {
return null;
}
return " → " + title + "|" + found[1].permalink + "\n"; // seemed like found[0] matches the current draft
}
let permalinked_lines = (d) => {
let content = draft.processTemplate("[[selection]]");
content = content.replace(wiki_re, (match, title) => {
let d = findLinkedDraft(title);
if (d) {
return d;
}
else { // not found, leave as-is
return match;
}
});
return content;
}
let lines = permalinked_lines(draft);
let taskpaper = '';
lines.split("\n").forEach(function(line) {
if (line.startsWith('- [ ]')) {
if (line.match(note_re)) {
let l = line.split(note_re);
line = l[0] + "\n" + l[1];
}
taskpaper += line.replace('[ ]', '') + "\n";
}
});
const baseURL = "omnifocus://x-callback-url/paste";
let cb = CallbackURL.create();
cb.baseURL = baseURL;
cb.addParameter("content", taskpaper.trim());
cb.open();