Skip to content

Instantly share code, notes, and snippets.

@zsviczian
Last active March 16, 2024 18:57
Show Gist options
  • Save zsviczian/fd3fcae4e2c4fa2be668756dca59da06 to your computer and use it in GitHub Desktop.
Save zsviczian/fd3fcae4e2c4fa2be668756dca59da06 to your computer and use it in GitHub Desktop.
Daily note taking scripts

These are the scripts referenced in my youtube video: ITS ABOUT TIME - How I integrate time into my Obsidian notes - GTD

  • meeting-note.md is the Templater script to create a new meeting note
  • section-tasks.md is a Templater script to create a Tasks section in your Obsidian note file
  • transclusion.css is an Obsidian CSS snippet to remove border box and scrollbar from around transclusions

<%* /*

*/
const view = app.workspace.activeLeaf.view;
const editor = view.editor;
const curLineNum = editor.getCursor().line;
const curLineText = editor.getLine(curLineNum);
const title = tp.file.title;
const today = title.match(/\d{4}\-\d{2}\-\d{2} .+/) //are we on the DNP?
  ? null //if on the DNP, today is set to null
  : moment(Date.now()).format("YYYY-MM-DD dddd"); //set today
let newLineText = curLineText.replace(
  /!?\[\[([^\]\|]*\/)?([^\]\|\/]+)\|?([^\]]*)?\]\]/, 
  (match,p1,p2,p3) => `${today?"###":"##"} ${p3??p2}\n![[${(p1??"")+p2}#${(today?today+" ":"") + title}]]`
);
editor.setLine(curLineNum, newLineText);
let fname = newLineText.match(/!\[\[(.*?)#.*?]]/)[1];
let file = app.metadataCache.getFirstLinkpathDest(fname,view.file.path);

if(!file) {
  if(!fname.endsWith(".md")) fname=fname+".md";
  file = await app.vault.create(fname,"# Notes\n");
}

const data = await app.vault.read(file);
const parts = data.split(/# Notes(?:\n|\r\n|\r)/);
newLineText = `## ${today?"[["+today+"]], ":""}[[${title}]]`;
if(parts.length === 2) {
  await app.vault.modify(file,parts[0]+"# Notes\n"+newLineText+"\n\n"+parts[1]);
} else {
  await app.vault.modify(file,data+"# Notes\n"+newLineText+"\n\n");
}

await app.workspace.openLinkText(fname, view.file.path);
let i=0;
const lineCount = editor.lineCount();
while(editor.getLine(i)!==newLineText && i<lineCount) i++;
editor.setCursor(i+1);
%>
# Tasks
```dataviewjs
//<% Math.round(Math.random()*10**15) %>
const name = dv.current().file.name;
dv.taskList(dv.pages().file.tasks.where(t => !t.completed && t.text.includes(name)));
```
.markdown-embed-content {
max-height: none !important;
}
.markdown-source-view .markdown-embed,
.markdown-source-view .file-embed {
border: inherit;
padding: 0px 5px;
border-radius: 0px;
}
.markdown-embed {
padding-left: 10px !important;
padding-right: 10px !important;
margin-left: 0px !important;
margin-right: 0px !important;
}
.markdown-embed .markdown-preview-view {
padding: 0px;
}
.internal-embed {
backdrop-filter: brightness(0.8);
padding-left: 30px;
}
.markdown-embed-title {
display: none;
}
.markdown-embed-link, .file-embed-link {
right: 8px;
}
@captaincanuk
Copy link

I know it has been a year since you recorded this video. Does your workflow still work the same, or maybe you have made further improvements? I have loaded the 3 scripts but I am still having trouble getting obsidian to jump from daily notes to the project or person. Could you please screenshot the plugins that this depends on and what their settings are. It would be extremely helpful. I am new to Obsidian and Templater but have 20+ years of project management experience. What you have designed here is fantastic. thank you.
In the mean time, I am manually creating the links, sections and tasks.

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