Action

crosslink Todoist task & DTTG document

Posted by FlohGro, Last update almost 3 years ago

UPDATES

almost 3 years ago

prevented execution on the mac

show all updates...

almost 3 years ago

prevented execution on the mac

over 3 years ago

name updated

created by @FlohGro / more on my Blog

crosslink Todoist task & DTTG document

This action will create a cross-linked Task between Todoist and a DEVONthink document.

NOTE: this action will NOT work on macOS since the URL scheme of DEVONthink doesn’t support this

A new markdown document will be created in DTTG from the content of the current draft with the first line as title.

The DEVONthink item will be created in the global inbox.

After the document is created the action will create a new task in the inbox of your Todoist account with the title of the markdown document as task name. The task will contain a clickable link to open the corresponding DEVONthink document

When the task was created the action will prepend a link to it into the created markdown document.

known “issue”: if you quickly open the link to the Todoist task after the action prepended the link to the task to the Craft document, your Todoist app may show an error telling you that the task could not be found. The reason for this is, that Todoist needs to sync the created task to your app first (the task is created via the REST API). After the task was synced, the error won’t occur again.

[Configuration]

no configuration needed just install the action (and have DTTG installed on your iPhone.

Technically it would be possible to directly create the DEVONthink item in another group but it would need individual configuration. If you need this please reach out to me.

[Usage]

Use this action to create a cross-linked task / document between your task manager and DEVONthink. If you e.g. took some notes during a meeting or while reading a book / blog in Drafts which you need to review or complete later - just run this action. It will help you to quickly navigate between the task and the document without seeing distracting other content.


If you find this useful and want to support me you can

Buy Me A Coffee

Steps

  • script

    // cross linked DEVONthink item and todoist task
    
    let title = draft.displayTitle
    
    let encodedTitle = encodeURIComponent(title)
    
    let content = draft.content
    
    //content = encodeURIComponent(content)
    
    var proceed = true;
    
    if (device.model == "Mac") {
    proceed = false;
    alert("can't run this action on the mac - the url scheme doesn't support this");
    context.fail("can't run this action on the mac - the url scheme doesn't support this");
    }
    
    const dttgCreateMarkdownBaseURL = "x-devonthink://x-callback-url/createmarkdown?"
    const dttgUpdateDocumentBaseURL = "x-devonthink://x-callback-url/update?"
    
    if (proceed){
    
    
    var cbCreateDttgDoc = CallbackURL.create()
    cbCreateDttgDoc.baseURL = dttgCreateMarkdownBaseURL
    // unused - will be sent to global inbox cbCreateDttgDoc.addParameter("destintaion", destinationUUID)
    cbCreateDttgDoc.addParameter("title", title)
    cbCreateDttgDoc.addParameter("text", content)
    cbCreateDttgDoc.waitForResponse = true
    
    var dttgCreateReturn = cbCreateDttgDoc.open()
    
    if (dttgCreateReturn == true) {
        console.log("DTTG document successfully created")
    } else {
        proceed = false
        console.log("DTTG create document result:" + cb.status + " " + cb.callbackResponse)
        if (cb.status == "cancelled") {
            context.cancel()
        } else {
            context.fail()
        }
    }
    
    }
    
    // craft note is created, now create the todoist task by using the REST API
    if (proceed) {
    
        // retrieve info from craftCreateResult
        let dttgCreateReturn = cbCreateDttgDoc.callbackResponse
    
        var dttgDocumentLink = dttgCreateReturn["text"]
    
        let taskNoteStr = "DTTG Document: " + dttgDocumentLink
        let taskTitle = "[" + title + "](" + dttgDocumentLink + ")"
    
        let todoist = Todoist.create();
    
        var todoistAddResult = todoist.quickAdd(taskTitle);
        if (!todoistAddResult) {
            let message = "Failed to add Task to todoist: " + todoist.lastError;
            console.log(message)
            context.fail(message);
            app.displayErrorMessage(message);
            proceed = false
        } else {
            console.log("Successfully created todoist Task")
        }
    }
    
    // things task added now prepend the link to the previously created craft note
    if (proceed) {
    
        // retrieve info from todoistAddResult
        let taskID = todoistAddResult["id"]
    
        let showTaskUrl = "todoist://task?id=" + taskID
    
        let openTaskStr = "> Task in Todoist: [" + title + "](" + showTaskUrl + ")"
    
        let encodedBlockContent = encodeURIComponent(openTaskStr)
    
    
    
        dttgDocumentUUID = dttgDocumentLink.replace("x-devonthink-item://", "")
    
        let newContent = draft.title + "\n\n" + openTaskStr + "\n\n" + draft.processTemplate("[[body]]")
    
        let encodedContent = encodeURIComponent(newContent)
    
        var cbUpdateDTTGDocument = CallbackURL.create()
        cbUpdateDTTGDocument.baseURL = dttgUpdateDocumentBaseURL
        cbUpdateDTTGDocument.addParameter("uuid", dttgDocumentUUID)
        cbUpdateDTTGDocument.addParameter("text", newContent)
        cbUpdateDTTGDocument.waitForResponse = true
    
        dttgUpdateReturn = cbUpdateDTTGDocument.open()
    
    
        if (dttgUpdateReturn == true) {
            console.log("DTTG document successfully updated")
        } else {
            proceed = false
            console.log("DTTG document update failed: " + cb.status + " " + cb.callbackResponse)
            if (cb.status == "cancelled") {
                context.cancel()
            } else {
                context.fail()
            }
        }
    
    }

Options

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