Skip to content

Instantly share code, notes, and snippets.

@selfire1
Created February 27, 2022 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selfire1/8d1db12f1a2fe9fb6b6b7b9c3f2ee59c to your computer and use it in GitHub Desktop.
Save selfire1/8d1db12f1a2fe9fb6b6b7b9c3f2ee59c to your computer and use it in GitHub Desktop.
A script for Templater to copy the line to a weekly note. Change the variables to your setup

<%* // Select active line // Source: https://gist.github.com/GitMurf/c52dfef13162d88375975e4eefedf3a7 const editor = app.workspace.activeLeaf.view.editor; const curLineNum = editor.getCursor().line; editor.setSelection({ line: curLineNum, ch: 0 }, { line: curLineNum, ch: editor.getLine(curLineNum).length }); let copiedStr = editor.getSelection(); copiedStr = copiedStr.trim();

// Replace formatting copiedStr = copiedStr.replace(/[*-]\s/, "")

// Append to Weekly var appendFile = ${tp.date.now("YYYY")}-W${tp.date.now("WW")}; const append = * [[${tp.file.title}|${moment(tp.file.title).format("ddd (MMM D)")}]]: ${copiedStr}; //text to append tp.date.now var template = tp.file.find_tfile("✂️ Weekly Template"); const folder = app.vault.getAbstractFileByPath("20 Journals/2022");

// Create if non-existent if (!tp.file.exists(appendFile)) { await tp.file.create_new(template, appendFile, false, folder) new Notice('🆕Created new Weekly!'); } // Append to file const originalContent = await app.vault.read(tp.file.find_tfile(appendFile)); const contentNew = ${originalContent}\n${append} await app.vault.modify(tp.file.find_tfile(appendFile), contentNew) new Notice('📌Appended to Weekly!'); // Print string tR = * ${copiedStr} ([[${appendFile}|📅]]); %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment