Plug-In: Add to Obsidian

(Requires OmniFocus 4.x)

A plug-in 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.

This plug-in creates a new note in the indicated vault within the Obsidian application containing the title and note of the selected OmniFocus project or task. Link-backs are inserted into both the Obsidian note and the OmniFocus task/project note, so navigating between the applications is easy. Also, the link-backs work even if the note is renamed!

In addition, there is a plug-in preference for adding the assigned task tags to the created Obsidian note.

(⬇ see below ) The task in OmniFocus:

OmniFocus Task

(⬇ see below ) The task as a note in Obsidian:

New note in Obsidian

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.

To include the assigned task tags with the created note, select the checkbox titled: Include OmniFocus tags with note

If you’ve installed the 3rd-party “Advanced Obsidian URI” Obsidian plug-in, select the corresponding checkbox to have the link-back inserted into the OmniFocus note adjusted accordingly to work with the Obsidian plug-in.

(⬇ see below ) The plug-in preferences dialog:

The plug-in preferences dialog

Related Obsidian documentation:

Revision

Return to: OmniFocus Plug-In Collection

Add to Obsidian
  

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.of.task-to-obsidian", "version": "2.4", "description": "Creates a corresponding note in the indicated Obsidian vault, for the selected task or project. Three is a preference for including the tags assigned to the task or project.", "label": "Add to Obsidian", "shortLabel": "Add to Obsidian", "paletteLabel": "Add to Obsidian", "image": "note.text.badge.plus" }*/ (() => { const preferences = new Preferences() var shouldUseNoFormatting const action = new PlugIn.Action(async function(selection, sender){ try { if(app.userVersion.isBefore(new Version("4"))){ var shouldUseNoFormatting = true } else { var shouldUseNoFormatting = false } if (app.controlKeyDown){ var errorID = "A" vaultTitle = preferences.readString("vaultTitle") var vaultTitleInput = new Form.Field.String( "vaultTitle", null, vaultTitle, null ) shouldIncludeTagsValue = preferences.readBoolean("shouldIncludeTags") var includeTagsCheckbox = new Form.Field.Checkbox( "shouldIncludeTags", "Include OmniFocus tags with note", shouldIncludeTagsValue ) shouldRequireURIPluginValue = preferences.readBoolean("shouldRequireURIPlugin") var requireURIpluginCheckbox = new Form.Field.Checkbox( "shouldRequireURIPlugin", "Use with the “Advanced Obsidian URI” plug-in", shouldRequireURIPluginValue ) inputForm = new Form() inputForm.addField(vaultTitleInput) inputForm.addField(includeTagsCheckbox) inputForm.addField(requireURIpluginCheckbox) formPrompt = "Enter title of the existing Obsidian vault to use:" formObject = await inputForm.show(formPrompt,"Continue") newVaultTitle = formObject.values["vaultTitle"] newShowTags = formObject.values["shouldIncludeTags"] newshouldRequireURIPlugin = formObject.values["shouldRequireURIPlugin"] preferences.write("vaultTitle", newVaultTitle) preferences.write("shouldIncludeTags", newShowTags) preferences.write("shouldRequireURIPlugin", newshouldRequireURIPlugin) } 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 shouldIncludeTags = preferences.readBoolean("shouldIncludeTags") if(!shouldIncludeTags){shouldIncludeTags = false} console.log("Pref-shouldIncludeTags: ", shouldIncludeTags) var shouldRequireURIPlugin = preferences.readBoolean("shouldRequireURIPlugin") if(!shouldRequireURIPlugin){shouldRequireURIPlugin = false} console.log("Pref-shouldRequireURIPlugin: ", shouldRequireURIPlugin) item = selection.databaseObjects[0] itemID = item.id.primaryKey itemLink = `omnifocus:///task/${itemID}` itemTitle = item.name itemNote = item.note mdLink = `[(OmniFocus Link)](${itemLink})` encodedLink = encodeURIComponent(mdLink) encodedTitle = encodeURIComponent(itemTitle) encodedNote = encodeURIComponent(itemNote) encodedVaultTitle = encodeURIComponent(vaultTitle) encodedTags = null if(shouldIncludeTags && item.tags.length > 0){ tagTitles = item.tags.map(tag => tag.name) tagArrayStr = `[${tagTitles.join(", ")}]` YAMLheader = `---\nid: ${itemID}\ntags: ${tagArrayStr}\n---` } else { YAMLheader = `---\nid: ${itemID}\n---` } encodedHeader = encodeURIComponent(YAMLheader) if(shouldRequireURIPlugin){ searchLinkStr = `obsidian://advanced-uri?vault=${encodedVaultTitle}&uid=${itemID}` } else { searchLinkStr = `obsidian://search?vault=${encodedVaultTitle}&query=${itemID}` } console.log("Search URL: ", searchLinkStr) if(shouldUseNoFormatting){ item.note = searchLinkStr + "\n\n" + item.note } else { noteObj = item.noteText linkURL = URL.fromString(searchLinkStr) linkObj = new Text("(Obsidian Link)", noteObj.style) newLineObj = new Text("\n", noteObj.style) style = linkObj.styleForRange(linkObj.range) style.set(Style.Attribute.Link, linkURL) noteObj.insert(noteObj.start, linkObj) noteObj.insert(linkObj.range.end, newLineObj) } targetLink = `obsidian://new?vault=${encodedVaultTitle}&name=${encodedTitle}&content=${encodedHeader}%0A%0A${encodedLink}%0A%0A${encodedNote}` console.log("Create URL: ", targetLink) URL.fromString(targetLink).open() } } catch(err){ if(errorID !== "A"){ new Alert(err.name, err.message).show() } } }); action.validate = function(selection, sender){ return ( selection.databaseObjects.length === 1 && selection.tasks.length === 1 || selection.projects.length === 1 ) }; return action; })();