×

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.0", "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" }*/ (() => { var 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" } var itemID = selectedItem.id.primaryKey var itemTitle = selectedItem.name var itemMarkdown = `[${itemTitle}](omnifocus://task/${itemID})` var checkboxSwitch = new Form.Field.Checkbox( "shouldIncludeSubTasks", "Include links to sub-tasks", true ) var inputForm = new Form() inputForm.addField(checkboxSwitch) var formPrompt = "Copy Markdown Links to Clipboard:" var buttonTitle = "Continue" var formObject = await inputForm.show(formPrompt, buttonTitle) var 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")){ await new Alert(err.name, err.message).show() } throw `${err.name}\n${err.message}` } }); action.validate = function(selection, sender){ // validation code // selection options: tasks, projects, folders, tags, allObjects return (selection.tasks.length + selection.projects.length === 1) }; return action; })();