Action

Send to DevonThink and OmniFocus

Posted by mhodgkinsonrowe, Last update almost 3 years ago

Exports the current draft to DevonThink as markdown and creates any open tasks in the OmniFocus inbox. Tasks are indented based on header level.

Steps

  • script

    // See online documentation for examples
    // https://docs.getdrafts.com/docs/actions/scripting
    
    let tasks = '';
    let cleaned_title = '';
    let indent_level = 0;
    let task_indentifier = '[ ]';
    
    
    function createTaskpaper(line, index) {
    
    	if (line.startsWith('# ')) {
    		cleaned_title = line.replace('# ', '')
    		tasks += cleaned_title + "\n"
    		indent_level = 0
    	}
    	
    	if (line.startsWith('## ')) {
    		tasks += "\t" + line.replace('## ', '').trim() + "\n"
    		indent_level = 1
    	}
    	
    	if (line.startsWith('### ')) {
    		tasks += "\t\t" + line.replace('### ', '').trim() + "\n"
    		indent_level = 2
    	}
    	
    	if (line.startsWith('#### ')) {
    		tasks += "\t\t\t" + line.replace('#### ', '').trim() + "\n"
    		indent_level = 3
    	}
    	
    	if (line.startsWith('[ ]')) {
    		tasks += "\t".repeat(indent_level + 1) + line.replace(task_indentifier, '').trim() + "\n";
    	}
    }
    
    draft.content.split("\n").forEach(createTaskpaper);
    draft.setTemplateTag("tasks", tasks.trim());
    draft.setTemplateTag("cleanedtitle", cleaned_title);
    
    
    // Two URL actions to follow script:
    // 
    // omnifocus:///paste?content=[[tasks]]
    // x-devonthink://createmarkdown?title=[[cleanedtitle]]&text=[[draft]]&tags=[[tags]]
  • url

    template
    omnifocus:///paste?content=[[tasks]]
    useSafari
    false
    encodeTags
    true
  • url

    template
    x-devonthink://createmarkdown?title=[[cleanedtitle]]&text=[[draft]]&tags=[[tags]]
    useSafari
    false
    encodeTags
    true

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.