crosslink Omnifocus task and Craft document

Posted by FlohGro, Last update 7 months ago


7 months ago

fix cb url issue

show all updates...

7 months ago

fix cb url issue

over 2 years ago

typo fixed

over 2 years ago

  • name changed
  • now using credential store for the Craft space id
  • description update

created by @FlohGro / more on my Blog

crosslink Omnifocus task and Craft document

This action will create a cross-linked Task between Omnifocus and a Craft document.

A new Craft document will be created from the content of the current draft with the first line as title for the document.

After the document is created the action will create a new task in the inbox of your Omnifocus account with the title of the Craft document as task name. The task will contain note with a link to the created Craft document

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


If you don’t want to use the (any of my) action for different Craft spaces there is no configuration needed. When you first run any of my Craft actions it will ask you to store the space id of your Craft space. This is a one time action and you don’t need to do it for any other oof my Craft actions you install.

To use these actions with different spaces you need to duplicate the action for each space you want to use it. I recommend to e.g. add a suffix to the action name to describe the space for which you configure it.

The action uses Drafts possibility to store credentials to distinguish different spaces. When you duplicate the action for another space you have to change the name of the credential. Therefore you need edit this line const spaceIdCredentialName = "CraftDocumentSpace" in the script step of the action and change the CraftDocumentSpace to something different (e.g. describe the space in a suffix like „CraftDocumentSpacePersonal" or „CraftDocumentSpaceWork“. If you use several of my Craft actions you should use the same credential name in all of them.


Use this action to create a cross-linked task / document between your task manager and Craft. 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


  • script

    // cross linked craft note and omnifocus task
    // optional configuration of the spaceIdCredentialName - only necessary if you want to use the same action for different Craft Spaces
    const spaceIdCredentialName = "CraftDocumentSpace"
    let spaceID = getCraftSpaceIdToUse();
    let title = draft.displayTitle
    let encodedTitle = encodeURIComponent(title)
    let content = draft.content
    content = encodeURIComponent(content)
    var proceed = true;
    const craftCreateBaseURL = "craftdocs://x-callback-url/createdocument?"
    const craftCreateBlockBaseURL = "craftdocs://createblock?"
    const omnifocusAddBaseURL = "omnifocus:///add?"
    var cbCreateCraftNote = CallbackURL.create()
    cbCreateCraftNote.baseURL = craftCreateBaseURL
    cbCreateCraftNote.addParameter("spaceId", spaceID)
    cbCreateCraftNote.addParameter("title", title)
    cbCreateCraftNote.addParameter("content", content)
    cbCreateCraftNote.addParameter("folderId", "")
    cbCreateCraftNote.waitForResponse = true
    let craftCreateReturn =
    if (craftCreateReturn == true) {
        console.log("Craft note successfully created")
    } else {
        proceed = false
        console.log("Craft note result:" + cbCreateCraftNote.status + " " + cbCreateCraftNote.callbackResponse)
        if (cbCreateCraftNote.status == "cancelled") {
        } else {
    // craft note is created, now create the omnifocus task
    if (proceed) {
        // retrieve info from craftCreateResult
        let craftCreateResult = cbCreateCraftNote.callbackResponse
        var blockId = craftCreateResult.blockId
        var craftNoteLink =
        let taskNoteStr = "Craft Note: " + craftNoteLink
        var cbAddOmnifocusTask = CallbackURL.create()
        cbAddOmnifocusTask.baseURL = omnifocusAddBaseURL
        cbAddOmnifocusTask.addParameter("name", title)
        cbAddOmnifocusTask.addParameter("note", taskNoteStr)
        cbAddOmnifocusTask.addParameter("autosave", "true")
        cbAddOmnifocusTask.waitForResponse = true
        let omnifocusAddReturn =
        if (omnifocusAddReturn == true) {
            console.log("Omnifocus Task successfully created")
        } else {
            proceed = false
            console.log("Add Omnifocus task result:" + cbAddOmnifocusTask.status + " " + cbAddOmnifocusTask.callbackResponse)
            if (cbAddOmnifocusTask.status == "cancelled") {
            } else {
    // omnifocus task added now prepend the link to the previously created craft note
    if (proceed) {
        // retrieve info from craftCreateResult
        let omnifocusAddResult = cbAddOmnifocusTask.callbackResponse
        let showTaskUrl = omnifocusAddResult["result"]
        let openTaskStr = "> Task in Omnifocus: [" + title + "](" + showTaskUrl + ")"
        let encodedBlockContent = encodeURIComponent(openTaskStr)
        var cbCreateCraftBlock = CallbackURL.create()
        cbCreateCraftBlock.baseURL = craftCreateBlockBaseURL
        cbCreateCraftBlock.addParameter("spaceId", spaceID)
        cbCreateCraftBlock.addParameter("parentBlockId", blockId)
        cbCreateCraftBlock.addParameter("index", "0")
        cbCreateCraftBlock.addParameter("content", encodedBlockContent)
        cbCreateCraftBlock.waitForResponse = false
    function getCraftSpaceIdToUse() {
        let credential = Credential.create(spaceIdCredentialName, "Credential to store the spaceId of the space you want to use in Drafts.\ninsert your spaceId into the TextField below. \n\nNOTES: \n- this is a one time action, you don't need to do it everytime\n- Multiple spaces are currently not supported with this spaceId credential helper");
        credential.addTextField("spaceId", "spaceId");
        if (credential.authorize()) {
            return credential.getValue("spaceId");
        } else {
            let errorStr = "failed storing / retrieving space Id with credential"
            return false;


  • 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.