Action

ReadLater: NotePlan & Todoist

Posted by Alkomy, Last update 16 days ago

UPDATES

16 days ago

Update the callback link to open on Mac OS, iPad OS, & iOS

show all updates...

16 days ago

Update the callback link to open on Mac OS, iPad OS, & iOS

16 days ago

Key changes:

  • Use draft.title directly for the task content (it’s automatically the first line)

  • Use draft.content for the full NotePlan note

  • Split draft.content and take everything after the first line (lines.slice(1)) for the Todoist description

  • Removed the draft.processTemplate() calls which were causing the issue

about 2 months ago

Remove duplicate title, by using drafts body instead of drafts content.

Send draft to NotePlan as new note. Then create a new Task with NotePlan note’s link into Todoist

  • NotePlan content in Markdown.
  • Todoist Task Title: First Line
  • Todoist Description: Draft content + Link to note (easy to open note on Mac/iOS)

Steps

  • defineTemplateTag

    name
    content
    template
    [[body]]
  • script

    // Create a new note in NotePlan
    const noteplan = CallbackURL.create();
    noteplan.baseURL = "noteplan://x-callback-url/addNote";
    
    // Use the first line of the draft as the title in NotePlan
    noteplan.addParameter("noteTitle", draft.title);
    // Use the full content of the draft for the text
    noteplan.addParameter("text", draft.content);
    noteplan.addParameter("openNote", "no");
    
    const success = noteplan.open();
    if (success) {
        // Construct the NotePlan URL to open the created note
        const encodedTitle = encodeURIComponent(draft.title);
        const noteplanURL = "noteplan://x-callback-url/openNote?noteTitle=" + encodedTitle;
        
        // Create task in Todoist using Drafts Todoist integration
        var todoist = Todoist.create();
        
        // Extract first line and remaining content
        const lines = draft.content.split("\n");
        const remainingContent = lines.slice(1).join("\n").trim();
        
        let taskContent = draft.title; // First line as task title
        let taskDescription = remainingContent + "\n\n" + noteplanURL; // Rest + link
        
        let createTaskResponse = todoist.createTask({
            "content": taskContent,
            "description": taskDescription
        });
        
        if (!createTaskResponse) {
            let message = "Failed to add task to Todoist: " + todoist.lastError;
            console.log(message);
            context.fail(message);
            app.displayErrorMessage(message);
        } else {
            let message = "Successfully added task in Todoist";
            console.log(message);
            app.displaySuccessMessage("Successfully created note in NotePlan and task in Todoist!");
        }
    } else {
        // If NotePlan call fails, log the error
        console.log(noteplan.callbackResponse.errorMessage);
        context.fail();
    }

Options

  • After Success Archive
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.