Action
Today
Posted by taurean,
Last update
6 days ago
Creates or appends to a daily note with time stamped bullet points
Steps
-
script
// Fixed daily note script using simple tag filtering + date check let today = new Date(); // Filename format: YYYY-MM-DD let filename = today.getFullYear() + '-' + String(today.getMonth() + 1).padStart(2, '0') + '-' + String(today.getDate()).padStart(2, '0'); // Heading format: Month day, Year (wk week number) let months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; let monthName = months[today.getMonth()]; let day = today.getDate(); let year = today.getFullYear(); // Calculate week number (ISO week) let startOfYear = new Date(year, 0, 1); let pastDaysOfYear = (today - startOfYear) / 86400000; let weekNumber = Math.ceil((pastDaysOfYear + startOfYear.getDay() + 1) / 7); let heading = `# ${monthName} ${day}, ${year} (wk ${weekNumber})`; // Format current time as 2:31pm style let timeString = today.toLocaleTimeString('en-US', { hour: 'numeric', minute: '2-digit', hour12: true }).toLowerCase(); let timeEntry = `* ${timeString} - `; // Get today's date for comparison (without time) let todayDateOnly = new Date(today.getFullYear(), today.getMonth(), today.getDate()); // Search for drafts with "daily" tag let dailyDrafts = Draft.query("", "all", ["daily"], [], "created", true, false); // Find today's note by checking creation date let dailyDraft = null; for (let d of dailyDrafts) { let draftDate = new Date(d.createdAt.getFullYear(), d.createdAt.getMonth(), d.createdAt.getDate()); if (draftDate.getTime() === todayDateOnly.getTime()) { dailyDraft = d; break; } } if (dailyDraft) { // Found today's note, add new time entry dailyDraft.content += `\n${timeEntry}`; dailyDraft.update(); } else { // Create new note dailyDraft = new Draft(); dailyDraft.content = `${heading}\n\n${timeEntry}`; dailyDraft.addTag("daily"); dailyDraft.update(); } // Open the note and position cursor at the end editor.load(dailyDraft); editor.activate(); // Position cursor at the end of the content (after the dash and space) let endPosition = dailyDraft.content.length; editor.setSelectedRange(endPosition, 0);
Options
-
After Success Default Notification Info Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.