Action
New Linked Draft (jaymf)
Posted by sylumer,
Last update
about 3 years ago
- Unlisted
Steps
-
defineTemplateTag
name NEWDRAFTCONTENT
template ::::::::::::::::::::::::::::::::::::: Location: Drafts Community Attendees: Me + anyone else willing to help Date: [[[[date]]]] ::::::::::::::::::::::::::::::::::::: ## Agenda ## Notes ::::::::::::::::::::::::::::::::::::: ## Todoist Tasks - [ ] ## Action Plan / Agenda for Next Meeting ::::::::::::::::::::::::::::::::::::: --- ## Backlinks [[backlink]]
-
defineTemplateTag
name NEWDRAFTTITLEPREFIX
template #
-
script
// Initialise new draft content from custom template tag let strNewDraftTemplate = draft.getTemplateTag("NEWDRAFTCONTENT"); strNewDraftTemplate = strNewDraftTemplate.replaceAll("[[backlink]]", `[[${draft.displayTitle}]]`); // Propt user for new draft information let promptDraftInfo = Prompt.create(); promptDraftInfo.title = "Create Linked Draft" promptDraftInfo.message = "Create a new backlinked draft, and insert a link to the new draft at the current cursor position.\nSpecify the title and tags below." promptDraftInfo.addTextField("title", "Title", ""); promptDraftInfo.addTextField("tags", "Tags", draft.tags.join(", ")); promptDraftInfo.addButton("Create"); // If it was not cancelled, process the details if (promptDraftInfo.show()) { // Create new draft let draftNew = Draft.create(); draftNew.content = draft.getTemplateTag("NEWDRAFTTITLEPREFIX") + promptDraftInfo.fieldValues["title"] + "\n" + draftNew.processTemplate(strNewDraftTemplate); promptDraftInfo.fieldValues["tags"].split(",").map(strTag => draftNew.addTag(strTag.trim())); draftNew.update(); // Insert new draft link in current draft at cursor position let strLink = "[[" + draftNew.displayTitle + "]]"; editor.setSelectedText(strLink); // Push the cursor to the end of the selection editor.setSelectedRange(editor.getSelectedRange()[0] + editor.getSelectedRange()[1], 0); // Copy the draft link to the new draft to the clipboard app.setClipboard(strLink); // Load the new draft into the editor and activate it editor.load(draftNew); editor.activate(); }
Options
-
After Success Default Notification Error Log Level Error
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.