×

OmniOutliner and Obsidian

Omni Automation Plug-In: Outline to New Obsidian Note

By nature of its structure, Obsidian is designed to absorb and display hierarchical materials such as outlines from OmniOutliner. Using Omni Automation and the automation tools in Obsidian, it is possible to cross-link data between the two applications.

This OmniOutliner plug-in will create a new Obsidian note whose contents is the revealed outline elements as plain text with tab indents. A link to the created note will be added to the end of the outline.

DISCLAIMER: 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.

Setting the Plug-In Preferences

Since Obsidian uses vaults, the title of the targeted vault is stored as a plug-in preference. To set the preference, select the plug-in from the Automation menu while holding down the Control key. A prompt for entering the title of the target Obsidian vault will appear. Once the preference has been set, the vault will be targeted by the plug-in. To change the vault, access the preference and enter the title of the new targeted vault.

When the plug-in is executed it will add a new row to the end of the outline. This row will contain information about the Obsidian vault and the item title used. The Obsidian note will also contain a UUID to make the note identifiable regardless of whether its name is changed. In addition, the added row will contain a link that will perform a search in the designated vault for the corresponding UUID related to the sent outline.

Return to: Plug-In Collection

Exporting a linked OmniOutliner outline to Obsidian.
Outline to New Obsidian Note
 

/*{ "type": "action", "targets": ["omnioutliner"], "author": "Otto Automator", "identifier": "com.omni-automation.oo.outline-as-text-to-obsidian", "version": "1.0", "description": "This action will create a new Obsidian note whose contents is the revealed outline elements as plain text with tab indents. A link to the created note will be added to the end of the outline.", "label": "Outline to Obsidian", "shortLabel": "Outline to Obsidian", "paletteLabel": "Outline to Obsidian", "image":"note.text.badge.plus" }*/ (() => { 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) encodedVaultTitle = encodeURIComponent(vaultTitle) baseName = document.name fileTypeID = "public.plain-text" wrapper = await document.makeFileWrapper(baseName, fileTypeID) outlineContent = wrapper.contents.toString() encodedContent = encodeURIComponent(outlineContent) itemTitle = document.name encodedTitle = encodeURIComponent(itemTitle) UUID = (genVal() + genVal() + "-" + genVal() + "-3" + genVal().substr(0,2) + "-" + genVal() + "-" + genVal() + genVal() + genVal()).toUpperCase() sourceDocument = `OmniOutliner/${document.name}` frontMatter = `---\nid: ${UUID}\nfile: ${sourceDocument}\n---` encodedHeader = encodeURIComponent(frontMatter) targetURLStr = `obsidian://new?vault=${encodedVaultTitle}&name=${encodedTitle}&content=${encodedHeader}%0A%0A${encodedContent}` targetURL = URL.fromString(targetURLStr) fmtr = Formatter.Date.withFormat('yyyy-MM-dd-HH:mm-a') dateTimeStamp = fmtr.stringFromDate(new Date()) exportID = `Obsidian (${vaultTitle}) ${dateTimeStamp}` searchLinkStr = `obsidian://search?vault=${encodedVaultTitle}&query=${UUID}` searchURL = URL.fromString(searchLinkStr) rootItem.addChild( null, item => { item.topic = exportID + " " link = new Text("(Obsidian Link)", item.style) style = link.styleForRange(link.range) style.set(Style.Attribute.Link, searchURL) textObj = item.valueForColumn(outlineColumn) textObj.append(link) } ) targetURL.open() } } catch(err){ if(errorID !== "A"){ new Alert(err.name, err.message).show() } } }); action.validate = function(selection, sender){ // selection options: columns, document, editor, items, nodes, outline, styles return true }; return action; })();