×

Plug-Ins: OmniGraffle and Obsidian

A set plug-ins for working with the Obsidian note-taking application.

Mention of third-party websites and products is for informational purposes only and constitutes neither an endorsement nor a recommendation. OMNI-AUTOMATION.COM assumes no responsibility with regard to the selection, performance or use of information or products found at third-party websites. OMNI-AUTOMATION.COM provides this only as a convenience to our users. OMNI-AUTOMATION.COM has not tested the information found on these sites and makes no representations regarding its accuracy or reliability. There are risks inherent in the use of any information or products found on the Internet, and OMNI-AUTOMATION.COM assumes no responsibility in this regard. Please understand that a third-party site is independent from OMNI-AUTOMATION.COM and that OMNI-AUTOMATION.COM has no control over the content on that website. Please contact the vendor for additional information.

Plug-In: Canvas to New Obsidian Note

This plug-in exports the current OmniGraffle canvas to a new note created in the indicated Obsidian vault.

NOTE: The current PNG export settings for background transparency are used in the generation of the PNG image. (File > Export…)

The export settings in OmniGraffle

To set the plug-in preference for targeted Obsidian vault name, hold down the Control key when selecting the plug-in from the Automation menu.

Plug-In: Search for Canvas in Obsidian

This plug-in searches the indicated Obsidian vault using the ID assigned to the current canvas by the previous plug-in.

To set the plug-in preference for targeted Obsidian vault name, hold down the Control key when selecting the plug-in from the Automation menu.

Installing the Plug-Ins

Download and unpack the folder archive containing the plug-ins and place the folder in the your OmniGraffle plug-ins folder. The Automation menu will now display an “Obsidian” sub-menu containing the plug-ins.

Video: Working with Obsidian
Plug-ins for working with the Obsidian note-taking application.
Canvas to New Obsidian Note
 

/*{ "type": "action", "targets": ["omnigraffle"], "author": "Otto Automator", "identifier": "com.omni-automation.og.canvas-to-obsidian-note", "version": "1.0", "description": "Creates a new Obsidian note in the indicated vault containing a PNG of the current canvas.", "label": "Canvas to New Obsidian Note", "shortLabel": "Canvas to Obsidian", "paletteLabel": "Canvas to Obsidian", "image": "photo.artframe" }*/ (() => { const preferences = new Preferences() function genVal(){ return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1) } const action = new PlugIn.Action(async function(selection, sender){ try { if (app.controlKeyDown){ var errorID = "A" vaultTitle = preferences.readString("vaultTitle") var vaultTitleInput = new Form.Field.String( "vaultTitle", null, vaultTitle, null ) inputForm = new Form() inputForm.addField(vaultTitleInput) formPrompt = "Enter title of the existing Obsidian vault to use:" formObject = await inputForm.show(formPrompt,"Continue") newVaultTitle = formObject.values["vaultTitle"] preferences.write("vaultTitle", newVaultTitle) } else { var errorID = "B" var vaultTitle = preferences.readString("vaultTitle") if(!vaultTitle || vaultTitle === ""){ throw { name: "Undeclared Vault Preference", message: "A default Obsidian vault has not yet been indicated for this plug-in.\n\nRun this plug-in again, while holding down the Control key, to summon the preferences dialog." } } console.log("Pref-vaultTitle: ", vaultTitle) var encodedVaultTitle = encodeURIComponent(vaultTitle) // NOTE NAME itemTitle = selection.canvas.name var itemTitleInput = new Form.Field.String( "itemTitle", null, itemTitle, null ) inputForm = new Form() inputForm.addField(itemTitleInput) formPrompt = "Enter title for new Obsidian note:" formObject = await inputForm.show(formPrompt, "Continue") itemTitle = formObject.values["itemTitle"] encodedTitle = encodeURIComponent(itemTitle) // EXPORT CANVAS IMAGE TO CLIPBOARD cnvs = document.windows[0].selection.canvas exportName = cnvs.name + ".png" fileTypeID = "public.png" wrapper = await document.makeFileWrapper(exportName, fileTypeID) item = new Pasteboard.Item() item.setDataForType(wrapper.contents,TypeIdentifier.png) Pasteboard.general.clear() Pasteboard.general.addItems([item]) // EXTRACT CLIPBOARD IMAGE AS BASE64 data = Pasteboard.general.dataForType(TypeIdentifier.png) dataStr = data.toBase64() // GENERATE UUID // For calling it, stitch '3' in the 3rd group UUID = (genVal() + genVal() + "-" + genVal() + "-3" + genVal().substr(0,2) + "-" + genVal() + "-" + genVal() + genVal() + genVal()).toUpperCase() // CREATE AN IMAGE DATA URL imageDataURL = `<img alt="${UUID}" src="data:image/png;base64,${dataStr}"/>` encodedImageURL = encodeURIComponent(imageDataURL) // CREATE THE YAML FRONT MATTER FOR THE NOTE sourceDocument = `OmniGraffle/${document.name}` frontMatter = `---\nid: ${UUID}\nfile: ${sourceDocument}\n---` encodedHeader = encodeURIComponent(frontMatter) targetLink = `obsidian://new?vault=${encodedVaultTitle}&name=${encodedTitle}&content=${encodedHeader}%0A%0A${encodedImageURL}` // WRITE ID TO CANVAS METADATA selection.canvas.background.setUserData("id", UUID) // OPEN URL URL.fromString(targetLink).open() } } catch(err){ if(errorID !== "A"){ new Alert(err.name, err.message).show() } } }); action.validate = function(selection, sender){ return true }; return action; })();
Search for Canvas in Obsidian


/*{ "type": "action", "targets": ["omnigraffle"], "author": "Otto Automator", "identifier": "com.omni-automation.og.search-obsidian", "version": "1.0", "description": "Searches the indicated Obsidian vault using current canvas metadata.", "label": "Search for Canvas in Obsidian", "shortLabel": "Search Obsidian", "paletteLabel": "Search Obsidian", "image": "magnifyingglass.circle" }*/ (() => { const preferences = new Preferences() const action = new PlugIn.Action(async function(selection, sender){ try { if (app.controlKeyDown){ var errorID = "A" vaultTitle = preferences.readString("vaultTitle") var vaultTitleInput = new Form.Field.String( "vaultTitle", null, vaultTitle, null ) inputForm = new Form() inputForm.addField(vaultTitleInput) formPrompt = "Enter title of the existing Obsidian vault to use:" formObject = await inputForm.show(formPrompt,"Continue") newVaultTitle = formObject.values["vaultTitle"] preferences.write("vaultTitle", newVaultTitle) } else { var errorID = "B" var vaultTitle = preferences.readString("vaultTitle") if(!vaultTitle || vaultTitle === ""){ throw { name: "Undeclared Vault Preference", message: "A default Obsidian vault has not yet been indicated for this plug-in.\n\nRun this plug-in again, while holding down the Control key, to summon the preferences dialog." } } console.log("Pref-vaultTitle: ", vaultTitle) var encodedVaultTitle = encodeURIComponent(vaultTitle) var searchKey = "id" var searchString = selection.canvas.background.userData[searchKey] if(!searchString){ throw { name: "Metadata Issue", message: `No metadata for the key “${searchKey}” has beeen assigned to the current canvas.` } } var encodedSearchString = encodeURIComponent(searchString) searchLinkStr = `obsidian://search?vault=${encodedVaultTitle}&query=${encodedSearchString}` console.log("Search URL: ", searchLinkStr) URL.fromString(searchLinkStr).open() } } catch(err){ if(errorID !== "A"){ new Alert(err.name, err.message).show() } } }); action.validate = function(selection, sender){ return true }; return action; })();