×

OmniFocus Plug-In: New Document with Project

Creates a new document in the Craft application using the data from the selected OmniFocus project.

New Document with Project
Creates a new document in the Craft application using the data from the selected OmniFocus project.

Return to: Omni Automation and Craft

New Document with Project
 

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.of.new-craft-doc-for-project", "version": "1.2", "description": "Creates a new document in the Craft application using the data from the selected project.", "label": "New Craft Document with Project", "shortLabel": "Craft Document with Project", "paletteLabel": "Craft Document with Project", "image": "list.bullet.rectangle.fill" }*/ (() => { var action = new PlugIn.Action(async function(selection, sender){ // action code // tasks | projects | folders | tags | databaseObjects | allObjects project = selection.projects[0] projectID = project.id.primaryKey markdown = `* # [${project.name}](omnifocus:///task/${projectID})` if (project.note){ markdown += `\n\t| ${project.note}` } // supports up to 3 levels of tasks: project > task > task > task project.tasks.forEach(task => { markdown += `\n\t- [ ] ### ${task.name}` if(task.note){ markdown += `\n\t\t| ${task.note}` } if(task.hasChildren){ task.tasks.forEach(tsk => { markdown += `\n\t\t- [ ] ### ${tsk.name}` if(tsk.note){ markdown += `\n\t\t\t| ${tsk.note}` } if(tsk.hasChildren){ tsk.tasks.forEach(tk => { markdown += `\n\t\t\t- [ ] ### ${tk.name}` if(tk.note){ markdown += `\n\t\t\t\t| ${tk.note}` } }) } }) } }) var textInputField1 = new Form.Field.String( "documentTitle", "Title", null, null ) var textInputField2 = new Form.Field.String( "documentDescription", "Description", null, null ) var inputForm = new Form() inputForm.addField(textInputField1) inputForm.addField(textInputField2) prompt = "Title and description for new document:" buttonTitle = "Continue" inputForm.validate = function(formObject){ documentTitle = formObject.values['documentTitle'] if(!documentTitle){return false} else {return true} } formObject = await inputForm.show(prompt, buttonTitle) documentTitle = formObject.values['documentTitle'] documentDescription = formObject.values['documentDescription'] linkCaption = '(TAP|CLICK title to view source project in OmniFocus.)' if(!documentDescription){ markdown = linkCaption + "\n" + markdown } else { markdown = documentDescription + "\n" + linkCaption + "\n" + markdown } markdown = markdown.replace(/</g, "<") markdown = markdown.replace(/>/g, ">") console.log(markdown) docTitle = encodeURIComponent(documentTitle) docContent = encodeURIComponent(markdown) urlStr = `craftdocs://createdocument?title=${docTitle}&content=${docContent}` URL.fromString(urlStr).open() }); action.validate = function(selection, sender){ // validation code // tasks | projects | folders | tags | databaseObjects | allObjects return (selection.projects.length === 1) }; return action; })();