Modify An Obsidian Templater Script To Move Text Selection To New Note And Backlink -- 2

Job ID: 37559178

Budget: $30 – $250 USD

I am looking for a freelancer who can modify an Obsidian Templater script created by Obsidian Forum Member AlanG that will take the text that is selected in the current source note, move it to a chosen destination note, and then embed the new location back into the current note.

I am using Obsidian 1.4.16 on Windows with the Templater plugin.

This is the outcome I would like to achieve:
1. Select text
2. Use a hotkey that activates the Templater template / script
3. Script prompts for a filename of the new destination note (without .md extension)
4. A new destination note with the provided filename is created in the directory "activities/tasks"
5. Either:
A: Have Tasks template applied to the new destination note from "templates/tasks.md" by Templater
-OR-
B. Have the contents of "templates/tasks.md" copied to to the newly created file
NOTE: I have attempted to make a Templater script that created a file. However, the script created a blank file and did not automatically apply the template as it should. I have a folder template assigned and "Trigger Templater on new file creation" activated for the folder under the Templater settings. But, when I manually create a file in the "activities/tasks" directory, the template is properly applied.
6. Remove the existing script processes that prompts the user for a heading
7. Remove the existing script processes that looks for the user provided heading
8. Instead, look for the text "## #todo" (including whitespace - it is a H2 heading called #todo), create a new line immediately below this heading and append the text selection on the newly created line
9. Embed a link to the new location of the selected text in the destination note back where the selected text was originally in the source note (just as the original script was written to do)

Here is the original script:
Also see here: https://share.note.sx/tus76cc6
// Script Start
<%*
// Get the selected text
let text = app.workspace.activeEditor.getSelection()

// Get the desired file - credits to https://forum.obsidian.md/t/67901/4
const files = app.vault.getMarkdownFiles().map(file => {
const fileCache = app.metadataCache.getFileCache(file)
file.display = file.basename
if (fileCache?.frontmatter?.aliases) {
if (Array.isArray(fileCache.frontmatter.aliases)) {
file.display = `${file.basename}\n${fileCache.frontmatter.aliases.join(", ")}`
} else if (typeof fileCache.frontmatter.aliases === 'string') {
file.display = `${file.basename}\n${fileCache.frontmatter.aliases}`
}
}
return file
})
const destination = (await tp.system.suggester(files.map(x => x.display), files, false, 'Start typing any note name...', 10)).path

// Get the heading
let embed
const heading = await tp.system.prompt('Enter the new heading or escape/cancel to use a block reference')
if (heading) {
text = `\n\n## ${heading.trim()}\n\n${text.trim()}\n\n`
embed = `![[${destination.slice(0, -3)}#${heading}]]\n`
} else {
// Block reference
const ref = Math.random().toString(36).slice(2, 7)
text = `\n\n${text.trim()} ^${ref}\n\n`
embed = `![[${destination.slice(0, -3)}#^${ref}]]\n`
}

// Add the text to the destination note
await app.vault.adapter.append(destination, text)

// Replace the selection with an embedded link to the new location
app.workspace.activeEditor.editor.replaceSelection(embed)
-%>
// Script End

Obsidian destination directory for new notes: "activities/tasks"
Obsidian location of Move And Embed script template: "templates/move-and-embed.md"
Obsidian location of tasks template: "templates/tasks.md"

Contents of tasks.md
// Tasks.md Contents Start
---
title:
allDay: false
date:
startTime:
endTime:
due:
completed: false
tags:
- "#todo"
length:
billable: false
ondeck: false
my_one_thing: false
cancelled: false
source:
date_created:
affordability:
importance:
urgency:
context:
---
```timer
```


## #todo


##### Notes:


***
##### References:

// Tasks.md Contents End

Ideal skills and experience:
- Strong knowledge and experience with Obsidian and Templater.
- Proficiency in scripting in programming languages such as JavaScript.
- Attention to detail and ability to follow specific instructions.
- Strong communication skills to discuss and clarify project details.

If you are an experienced freelancer with the necessary skills, I would love to discuss the project further and provide more specific details.
Related categories: JavaScript CSS Git Regular Expressions Scripting