×

Plug-In: Clipboard to New Bear Note

This plug-in uses the Pasteboard class functions to create a new note with the clipboard text contents in the Bear application.

(example image below shows results of the Clipboard Objects to Markdown Links action)

obects-to-markdown
Clipboard to New Bear Note
 

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.of.send-clipboard-to-bear", "version": "1.0", "description": "Creates a new note in the Bear app with the text contents of the OmniFocus pasteboard.", "label": "Clipboard to Bear", "shortLabel": "Clip to Bear" }*/ (() => { 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 note:" 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 BearURL = `bear://x-callback-url/create?title=${noteTitle}&open_note=yes&text=${pasteboardString}` URL.fromString(BearURL).call(result => { var newNoteTitle = result.title var newNoteID = result.identifier var openNoteURLStr = `bear://x-callback-url/open-note?id=${newNoteID}` URL.fromString(openNoteURLStr).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; })();

Return to: OmniFocus Plug-In Collection