Plug-In: Clipboard Text to Drafts
This plug-in uses the Pasteboard class functions to create a new note with the clipboard text contents in the Drafts application.
The example image below shows the results of using the Clipboard Objects to Markdown Links plug-in to convert copied OmniFocus objects into markdown links replacing the existing clipboard contents, and then using the Clipboard Text to Drafts plug-in to create a new draft with the markdown content:

Return to: OmniFocus Plug-In Collection
Clipboard Text to Drafts
/*{
"type": "action",
"targets": ["omnifocus"],
"author": "Otto Automator",
"identifier": "com.omni-automation.of.clipboard-text-to-drafts",
"version": "1.0",
"description": "Creates a new note in the Drafts app with the text contents of the OmniFocus pasteboard.",
"label": "Clipboard to Drafts",
"shortLabel": "Clip to Drafts"
}*/
(() => {
var action = new PlugIn.Action(function(selection, sender){
// action code
// selection options: tasks, projects, folders, tags, allObjects
var date = new Date()
var dc = Calendar.current.dateComponentsFromDate(date)
var delimiter = "-"
var dateSlug = dc.month + delimiter + dc.day + delimiter + dc.year + " " + dc.hour + ":" + dc.minute
var textInputField = new Form.Field.String(
"noteTitle",
null,
"OmniFocus " + dateSlug
)
var inputForm = new Form()
inputForm.addField(textInputField)
var formPrompt = "Title for new draft:"
var buttonTitle = "Continue"
var formPromise = inputForm.show(formPrompt,buttonTitle)
inputForm.validate = function(formObject){
noteTitle = formObject.values['noteTitle']
return ((!noteTitle)?false:true)
}
formPromise.then(function(formObject){
try {
var noteTitle = formObject.values['noteTitle']
noteTitle = encodeURIComponent(noteTitle)
var pasteboardString = encodeURIComponent(Pasteboard.general.string)
var DraftsURLStr = `drafts5://x-callback-url/create?text=${noteTitle}%0A%0A${pasteboardString}`
URL.fromString(DraftsURLStr).call(result => {
console.log(result)
//--> "790A478C-66D9-4C8D-857D-5910D058C417"
var openDraftURLStr = `drafts5://x-callback-url/open?uuid=${result}`
URL.fromString(openDraftURLStr).open()
}, err => {
new Alert("SCRIPT ERROR", err.errorMessage).show()
console.error(err)
})
}
catch (err){console.error(err)}
})
formPromise.catch(function(err){
console.error("form cancelled", err.message)
})
});
action.validate = function(selection, sender){
// validation code
// selection options: tasks, projects, folders, tags, allObjects
return (Pasteboard.general.hasStrings)
};
return action;
})();