← [[Automated Notes|Intro]] ⦿ [[Prerequisites]] ⦿ [[Create a daily note|Create]] ⦿ [[Daily note with Time Tracking|Track]] ⦿ [[Weekly Notes|Weekly]] ⦿ [[Dynamic content|Dynamic]] ⦿ [[Reports|Reports]] ⦿ Samples → # Daily note with Time Tracking Where it starts to get really fun is when you can track your workday with your daily note. The first five minutes of my workday is spent creating a new note to record my start time, reviewing prior notes and tasklists, checking (but not responding, yet) mail, opening my calendar, and creating a plan for the day. The last thing I do before leaving is record my end time and logout. The key part of that workflow is tracking time, so here's how to enable it. ## Updating the template for time tracking Edit `Templates/daily.md` and add these to the frontmatter: ``` start_time: <% tp.date.now("HH:mm") %> end_time: breaks: 0 holiday: 0 vacation: 0 ``` >NB: you can make it easer to see frontmatter in the file itself by selecting "Source mode" from the note's ellipsis menu Now when you create a new daily note, the start_time will be set to the current time (demonstration of this is left as an exercise for the reader). You can, if you like, set the end_time manually at the end of your day, but to make it *easy* to set the end_time you need to invoke a script. ## Creating a script First you need to create the script and let Templater know where to find it. ```js async function updateEndTime(tp) { const file = tp.app.workspace.getActiveFile(); if (!file) { new Notice("❌ No active file"); return ""; } if (!tp.frontmatter.type || tp.frontmatter.type !== "daily") { new Notice("🤷‍♀️ Not a daily note (check frontmatter 'type')") return ""; } const currentTime = moment().format("HH:mm"); await tp.app.fileManager.processFrontMatter(file, (frontmatter) => { frontmatter.end_time = currentTime; }); new Notice(`✅ End time set to ${currentTime}`); return ""; } module.exports = updateEndTime; ``` - Under `Scripts` create a note called `update-end-time` - Copy the script above to the note - Right-click on the file and "Reveal in Finder" - Rename it to `update-end-time.js` You'll notice that Obsidian can't / won't edit files that aren't markdown, so the focus shifts away from the renamed note to the last known good note. If you're going to do a lot of scripting, you should find a good .js script editor or IDE. - Settings .. Community plugins .. Templater .. User script functions .. it should now say "Detected 1 User Script(s)" named `tp.user.update-end-time` ![[User script functions.png]] ## Enabling the script for use You have to have something that calls the script, which we accomplish with a template. We can't put it in the `daily` template because that runs at the start of the day, so we create a script to run at the end of the day, called `Templates/update-end-time.md` with this content: ``` <% await tp.user["update-end-time"](tp) %> ``` That's it. Go to Settings .. Templater .. Template hotkeys and put that file name in the Templates list: ![[Template hotkeys.png]] Hit the ⊕ button. This will take you to the Hotkey mapper. Search for Templater, and find the "Templater: *insert* update-end-time", hit the ⊕ button here and type ⌘⇧E. ![[Hotkey mapper.png]] Now, whenever you end your day, you just hit ⌘⇧E while in a day's daily note and it will record the current time in `end_time`. ## Daily time summary See the tips in [[Dynamic content]] to enable a daily time summary ← [[Create a daily note]] ⦿ [[Weekly Notes]] →