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)
Return to: OmniFocus Plug-In Collection
Clipboard to New Bear Note
/*{
"type": "action",
"targets": ["omnifocus"],
"author": "Otto Automator",
"identifier": "com.omni-automation.of.send-clipboard-to-bear",
"version": "1.1",
"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",
"paletteLabel": "Clip to Bear",
"image":"arrow.up.doc.on.clipboard"
}*/
(() => {
const action = new PlugIn.Action(async function(selection, sender){
date = new Date()
dc = Calendar.current.dateComponentsFromDate(date)
delimiter = "-"
dateSlug = dc.month + delimiter + dc.day + delimiter + dc.year + " " + dc.hour + ":" + dc.minute
textInputField = new Form.Field.String(
"noteTitle",
null,
"OmniFocus " + dateSlug
)
inputForm = new Form()
inputForm.addField(textInputField)
inputForm.validate = function(formObject){
noteTitle = formObject.values['noteTitle']
return ((!noteTitle)?false:true)
}
formPrompt = "Title for note:"
buttonTitle = "Continue"
formObject = await inputForm.show(formPrompt,buttonTitle)
noteTitle = formObject.values['noteTitle']
noteTitle = encodeURIComponent(noteTitle)
pasteboardString = encodeURIComponent(Pasteboard.general.string)
BearURL = `bear://x-callback-url/create?title=${noteTitle}&open_note=yes&text=${pasteboardString}`
URL.fromString(BearURL).call(result => {
newNoteTitle = result.title
newNoteID = result.identifier
openNoteURLStr = `bear://x-callback-url/open-note?id=${newNoteID}`
URL.fromString(openNoteURLStr).open()
}, err => {
new Alert("SCRIPT ERROR", err.errorMessage).show()
console.error(err)
})
});
action.validate = function(selection, sender){
return (Pasteboard.general.hasStrings)
};
return action;
})();