Stuck with passing data to Dayone

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

image

Any help will be appreciated.

Add the snap of the action og

As far as I know, Day One does not, and never has, supported callback URLs, either via the x-callback-url spec or other means.

You can still create that action, it just will not return to Drafts, and you should set waitForResponse to false on the Day One callback.

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.

The script is same as above, except the Boolean change

Pasting here with the change


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(match => `${match[1]} @tags(A - Goal)`)
    console.log(matches);

    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 = false;
    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()

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.

Thanks that helped, now I’m stuck with a different problem

Here is the updated script, as suggested I’ve flipped the flow




function createOfTasks() {
    var editorText = editor.getText();
    var matches = [...editorText.matchAll(/- \[ \] (.+)/g)]
    if (matches.length === 0) {
        context.cancel("No intentions specified");
    }

    const baseURL = "omnifocus://x-callback-url/paste";
    var cb = CallbackURL.create();
    cb.waitForResponse = true;
    cb.baseURL = baseURL;

    matches = matches.map(match => `${match[1]} @tags(A - Goal)`)
    console.log(matches);

    cb.addParameter("content", matches.join("\n"));
    var success = cb.open();
    if (success) {
        console.log("Event created");
        createDayone(editorText);
    } else { // something went wrong or was cancelled
        console.log(cb.status);
        if (cb.status == "cancelled") {
            context.cancel();
        } else {
            context.fail();
        }
    }
}

function createDayone(journal_entry) {
    var cb = CallbackURL.create();
    cb.baseURL = "dayone2://post";
    cb.waitForResponse = false;
    cb.addParameter("entry", journal_entry);
    cb.addParameter("journal", "Evaluation/Review");

    var success = cb.open();
    if (success) {
        console.log(journal_entry);
        console.log("Journal created");
    } else { // something went wrong or was cancelled
        console.log(cb.status);
        if (cb.status == "cancelled") {
            context.cancel();
        } else {
            context.fail();
        }
    }
}

createOfTasks()

Now this works on mac as expected, but on iPhone the tasks are created in OF but the dayone entry is empty.

I’ve tried console.log and in action log I’m able to the see the journal_entry being printed properly but the dayone app the entry is empty.

PS: Tried URL encoding too that didn’t work either.

Please ignore the above post, looks like a issue on day one, if template journals are enabled the entry from post is ignored.

This thread is good to close. Thank you so much for your quick support.