Plug-In: Copy Task/Project Link to Clipboard as Markdown

Here's an Omni Automation plug-in for OmniFocus that copies links to the selected item (task or project) along with links to the item’s sub-tasks, to the clipboard in Markdown format. Perfect for pasting into a Craft document, or other application that accepts Markdown content as input.

OmniFocus-Craft

Return to: OmniFocus Plug-In Collection

Copy Task/Project Link to Clipboard as Markdown
  

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.of.item-link-as-markdown", "version": "1.1", "description": "Copies a link to the selected task or project to the clipboard in Markdown format. There is an option to include links to the item’s sub-tasks as well.", "label": "Item Link as Markdown", "shortLabel": "Item Link as Markdown", "paletteLabel": "Item Link as Markdown", "image": "arrow.up.doc.on.clipboard" }*/ (() => { const action = new PlugIn.Action(async function(selection, sender){ try { if (selection.tasks.length === 1){ var selectedItem = selection.tasks[0] var objectType = "task" } else { var selectedItem = selection.projects[0] var objectType = "project" } itemID = selectedItem.id.primaryKey itemTitle = selectedItem.name itemMarkdown = `[${itemTitle}](omnifocus://task/${itemID})` checkboxSwitch = new Form.Field.Checkbox( "shouldIncludeSubTasks", "Include links to sub-tasks", true ) inputForm = new Form() inputForm.addField(checkboxSwitch) formPrompt = "Copy Markdown Links to Clipboard:" buttonTitle = "Continue" formObject = await inputForm.show(formPrompt, buttonTitle) shouldIncludeSubTasks = formObject.values["shouldIncludeSubTasks"] if(shouldIncludeSubTasks){ selectedItem.tasks.forEach(task => { var taskID = task.id.primaryKey var taskTitle = task.name var taskMarkdown = `- [${taskTitle}](omnifocus://task/${taskID})` itemMarkdown += "\n" + taskMarkdown }) } console.log(itemMarkdown) Pasteboard.general.string = itemMarkdown new Alert("Markdown","The item links as Markdown have been copied to the clipboard.").show() } catch(err){ if(!err.message.includes("cancelled")){ new Alert(err.name, err.message).show() } } }); action.validate = function(selection, sender){ return (selection.tasks.length + selection.projects.length === 1) }; return action; })();