Plug-In: Open Note in Drafts
Opens the text content of the note of the selected task or project in the Drafts application from Agile Tortoise Inc.
Return to: OmniFocus Plug-In Collection
Open Note in Drafts
/*{
"type": "action",
"targets": ["omnifocus"],
"author": "Otto Automator",
"identifier": "com.omni-automation.of.open-note-in-drafts",
"version": "1.0",
"description": "Opens the text content of the note of the selected task or project in the Drafts application from Agile Tortoise Inc.",
"label": "Open Note in Drafts",
"shortLabel": "Open Note in Drafts",
"paletteLabel": "Open Note in Drafts",
"image": "gearshape"
}*/
(() => {
var action = new PlugIn.Action(function(selection, sender){
// action code
// selection options: tasks, projects, folders, tags, allObjects
try {
if (selection.tasks.length === 1){
var item = selection.tasks[0]
} else {
var item = selection.projects[0]
}
var noteText = item.note
if(!noteText || noteText.length === 0){
throw {"name":"Missing Resource", "message":"The selected item has no note text."}
}
var encodedString = encodeURIComponent(noteText)
var DraftsURLStr = "drafts5://x-callback-url/create?text=" + encodedString
URL.fromString(DraftsURLStr).open()
}
catch(err){
new Alert(err.name, err.message).show()
}
});
action.validate = function(selection, sender){
// validation code
// selection options: tasks, projects, folders, tags, databaseObjects, allObjects
return (
selection.databaseObjects.length === 1 &&
(selection.databaseObjects[0] instanceof Project ||
selection.databaseObjects[0] instanceof Task)
)
};
return action;
})();