I’m trying to set one (to do) check for changes in today’s note. If they are - copie them for to do.
Things I have tried
I’m create a macro that writing the same line in both files, but I need to write to it twice. More than that, it is not set checkers to the same. So I think that I need something that would copie text from one note to another then it’s going out of focus. But l don’t know how. Pls help!
The first option is to use the text transporter plugin and the second option is to create a macro and create a capture choice 1 and capture choice 2 and enable the task option in both and the daily note path in capture choice 1 and to-do file path in capture choice 2 and then do something similar in capture format
capture choice 1
{{value:Enter the task}}
capture choice 2
{{value:Enter the task}}
By duplicating variables, you don’t have to rewrite the task again.
You can make a command for it, install the buttons plugin and then add something like this
```button
type command
name Update the filename
action Quickadd: (the name of the macro)
color default
class *[data-mode='source'] .view-action:first-child { background-color: orange; } *[data-mode='preview'] .view-action:first-child { background-color: yellow; }
Now I combined the first idea with text transporter module and third, with button. I made button in today daily note. It’s send selection to to-do.
And button in to-do. It’s send selection to daily.
That’s close to my beginning idea, but if I change something in to do, I wanna it’s to be updated in daily note. It may be not automatic - just command to replace block of daily with content of to do.
<%*
async function deleteLinesContainingWord() {
const filePath = "path/to/your/note.md"; // Path to the specified file
const noteFile = this.app.vault.getAbstractFileByPath(filePath); // Get the file using the path
if (!noteFile) return; // If the file is not found
// Prompt the user for the word
const word = await tp.system.prompt("Enter the task");
if (!word) return; // If no word is entered
// Read the content of the specified file
let text = await this.app.vault.read(noteFile);
// Split the text into lines
let lines = text.split('\n');
// Filter out lines that do not contain the specified word or the script itself
let filteredLines = lines.filter(line => !line.includes(word) && !line.includes("deleteLinesContainingWord"));
// Reassemble the text after filtering
let newText = filteredLines.join('\n');
// Write the new text to the file
await this.app.vault.modify(noteFile, newText);
}
// Call the function
deleteLinesContainingWord();
%>
As you can copy the script into two templates. In the first template, you can put the to do note path in the previous script , in the second template we can make this edit in the script
const dailyNote = await tp.system.prompt("Enter the Daily note")
const filePath = `path/to/your/daily/notes/${dailyNote}.md`; // Path to the specified file
The final script will be
<%*
async function deleteLinesContainingWord() {
const dailyNote = await tp.system.prompt("Enter the Daily note")
const filePath = `daily/notes/path/${dailyNote}.md`; // Path to the specified file
const noteFile = this.app.vault.getAbstractFileByPath(filePath); // Get the file using the path
if (!noteFile) return; // If the file is not found
// Prompt the user for the word
const word = await tp.system.prompt("Enter the task");
if (!word) return; // If no word is entered
// Read the content of the specified file
let text = await this.app.vault.read(noteFile);
// Split the text into lines
let lines = text.split('\n');
// Filter out lines that do not contain the specified word or the script itself
let filteredLines = lines.filter(line => !line.includes(word) && !line.includes("deleteLinesContainingWord"));
// Reassemble the text after filtering
let newText = filteredLines.join('\n');
// Write the new text to the file
await this.app.vault.modify(noteFile, newText);
}
// Call the function
deleteLinesContainingWord();
%>
You can create a command for them from the templater settings and create a button for each of them using this button
```button
type command
name Delete the task from daily note
action Templater: Insert (the final script path after making the command).md
color default
class *[data-mode='source'] .view-action:first-child { background-color: orange; } *[data-mode='preview'] .view-action:first-child { background-color: yellow; }
```button
type command
name Delete the task from to-do
action Templater: Insert (the first script path after making the command).md
color default
class *[data-mode='source'] .view-action:first-child { background-color: orange; } *[data-mode='preview'] .view-action:first-child { background-color: yellow; }
With this script, you can delete the task from the to do note if you want to make an edit and resubmit it again after making the edit using the text transporter plugin and the other way around , the script will ask you about the content of the task, go to the note and delete the task from the note , but when you make an edit from to do note to the daily note, you will be asked for the name of the daily note.
Put the delete task from to-do button in your daily note template and put the delete task from daily note button in to-do note so that when you want to make an edit, you delete the old task and resubmit it again in a more automated way than before.
May be there is another way. I want this cause I have a canvas that contains to-do. Cause I didn’t find a way to insert a dynamic link for today note - I made to-do note. Representation of actual to-da in canvas is final task.
That the first script only deletes the task from the to-do note and the final script not working ,then you must have made a mistake in the steps that I have written for you, because the final script will not find the daily note unless there is an incorrect path for your daily notes that you entered in the body of the script or you made a mistake in something else, and this is for two reasons, the first is that the two scripts are basically the same, but the difference lies in that the final script only asks you for the day that contains the task that you want to delete, this is the difference, and the second is that I tried the solution before I sent it and it worked well as shown here :
That the solution is fully functional but you want to delete the task from both notes
(meaning you want to merge the two scripts together),
then this script will do that :
<%*
async function deleteLinesContainingWord() {
// Phase 1: Delete the task from the to-do note
const initialFilePath = "path/to/your/note.md"; // Path to the to-do file
const initialNoteFile = this.app.vault.getAbstractFileByPath(initialFilePath); // Get the file using the path
if (!initialNoteFile) {
new Notice("The to-do note not found.");
return; // If the file is not found
}
// Prompt for the task to delete
const word = await tp.system.prompt("Enter the task to delete");
if (!word) {
new Notice("No Task entered.");
return; // If no word is entered
}
// Read the content of the specified file
let initialText = await this.app.vault.read(initialNoteFile);
// Split the text into lines
let initialLines = initialText.split('\n');
// Filter out lines that do not contain the task
let initialFilteredLines = initialLines.filter(line => !line.includes(word) && !line.includes("deleteLinesContainingWord"));
if (initialFilteredLines.length === initialLines.length) {
new Notice(`This task isn't in to-do note.`);
}
// Reassemble the text after filtering
let initialNewText = initialFilteredLines.join('\n');
// Write the new text to the file
await this.app.vault.modify(initialNoteFile, initialNewText);
// Phase 2: Delete the task from the daily note
const dailyNote = await tp.system.prompt("Enter the Daily note");
const dailyFilePath = `daily/notes/path/${dailyNote}.md`; // Path to the daily note
const dailyNoteFile = this.app.vault.getAbstractFileByPath(dailyFilePath); // Get the file using the path
if (!dailyNoteFile) {
new Notice("Daily note not found or there is an incorrect path inside the script.");
return; // If the file is not found
}
// Read the content of the daily file
let dailyText = await this.app.vault.read(dailyNoteFile);
// Split the text into lines
let dailyLines = dailyText.split('\n');
// Filter out lines that do not contain the task
let dailyFilteredLines = dailyLines.filter(line => !line.includes(word) && !line.includes("deleteLinesContainingWord"));
if (dailyFilteredLines.length === dailyLines.length) {
new Notice(`This task isn't in the entered daily note.`);
}
// Reassemble the text after filtering
let dailyNewText = dailyFilteredLines.join('\n');
// Write the new text to the file
await this.app.vault.modify(dailyNoteFile, dailyNewText);
}
// Call the function
deleteLinesContainingWord();
%>
Do the same steps with the previous script and put it in a button and this will fulfil your request.