Heads Up: This is ithe first time trying out drafts scripting reference.
I’m trying to create the draft as a dayone entry followed by pushing data into OmniFocus but after running callback URL for dayone the control doesn’t;t seem to return back. Not sure what I’m missing
Here is the code snippet
var editorText = editor.getText();
console.log(editorText);
var matches = [...editorText.matchAll(/- \[ \] (.+)/g)]
if (matches.length === 0) {
context.cancel("No intentions specified");
}
function createOfTasks() {
const baseURL = "omnifocus://x-callback-url/paste";
var cb = CallbackURL.create();
cb.waitForResponse = true;
cb.baseURL = baseURL;
matches = matches.map(entry => `${entry} @tags(A - Goal)`)
cb.addParameter("content", matches.join("\n"));
var success = cb.open();
if (success) {
console.log("Event created");
} else { // something went wrong or was cancelled
console.log(cb.status);
if (cb.status == "cancelled") {
context.cancel();
} else {
context.fail();
}
}
}
function createDayone() {
var cb = CallbackURL.create();
cb.baseURL = "dayone2:///post";
cb.waitForResponse = true;
cb.addParameter("entry", editorText);
cb.addParameter("journal", "Evaluation/Review");
var success = cb.open();
if (success) {
console.log("Journal created");
// createOfTasks();
} else { // something went wrong or was cancelled
console.log(cb.status);
if (cb.status == "cancelled") {
context.cancel();
} else {
context.fail();
}
}
}
createDayone()
It opens day one on mac and gets stuck like this before the timeout kicks in
Thanks that helped. Making it false made things work on mac.
On iPhone there is an issue, the action opens day one and gets stuck, looks like the behaviour is different on the two platforms. Any work-around for this ?
Can you share your actual final action script? Hard to troubleshoot without details. It would appear Drafts is still waiting for a response from another app.
You’ve got a flow problem. Opening URLs leaves the app, and if it is not a callback URL that waits for a response, then processing of the action continues and will not work reliably if you open other URLs, because Drafts is no longer the active app.
If you are opening a non-callback URL, like Day One’s, that leaves the app and doesn’t return, it has to be the last thing your action does or you run into problems.
If you flip your flow to create the OmniFocus task first, that callback will wait for a response, return to Drafts, and allow the flow to continue to open the Day One URL.