Action
Seinfeldian chain
Produces an alert containing a very simple Seinfeldian chain (https://lifehacker.com/jerry-seinfelds-productivity-secret-281626).
Requires a date in the title the drafts you want to track, and for those drafts to be tagged appropriately (set your tag(s) to track as variables in the script). Also, this currently only looks for “inbox” drafts.
Select year, month and tag in the prompt. In the alert that’s generated:
- Each row = 1 week.
- “>” indicates a day from the preceding month’s calendar.
- “x” indicates a day when you did the thing.
- “-” indicates a day you missed.
- “!” indicates today.
Suggestions for improvements welcomed.
Steps
-
script
// Update the following array with the tags you want to track for Seinfeld charts. For example, I log each of my workouts in Drafts. I also write poetry and prose. // For writers: this doesn't pay attention to different versions of documents, so really all you're tracking is NEW writing here. Editing doesn't count for the purposes of this tracker. var tags = ["workoutlog","poems","prose"] // https://stackoverflow.com/questions/13146418/find-all-the-days-in-a-month-with-date-object /** * @param {int} The month number, 0 based * @param {int} The year, not zero based, required to account for leap years * @return {Date[]} List with date objects for each day of the month */ function getDaysInMonth(month, year) { var date = new Date(year, month, 1); var days = []; while (date.getMonth() === month) { days.push(new Date(date).toString("yyyy-MM-dd")); date.setDate(date.getDate() + 1); } return days; } // https://forums.getdrafts.com/t/display-boxed-message-or-notification/5301/2 function msgbox(p_strTitle, p_strMessage) { let promptMessage = Prompt.create(); promptMessage.title = p_strTitle; promptMessage.message = p_strMessage; promptMessage.addButton("OK"); promptMessage.isCancellable = false; promptMessage.show(); } // prompt for month/year and tag to focus on... (if you're reading this from the future, you may wish to add more years to the following array... var years = ["2020","2019","2018"] var p = Prompt.create(); p.title = "Focus for chain"; var now = new Date(); let n = now.getMonth(); p.addPicker("altDate", "Start date", [["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],years],[n,0]) // p.addSelect("tag", "tag", ["workoutlog","poem","prose"], [], false) p.addPicker("tagPicker", "tag", [tags], []) p.addButton("chain"); var didSelect = p.show(); var tag = tags[p.fieldValues["tagPicker"][0]] var startDate = p.fieldValues["myDate"]; var altMonth = p.fieldValues["altDate"][0]; var altYears = years[p.fieldValues["altDate"][1]]; if (p.buttonPressed == "chain") { var month = altMonth // startDate.getMonth() var year = altYears // startDate.getFullYear() } let FirstDay = new Date(year, month, 1); let fDayNum = 6 if (FirstDay.getDay() != 0){fDayNum = FirstDay.getDay() -1} var today = new Date().toString("yyyy-MM-dd") function pad(n){return n<10 ? '0'+n : n} var qDate = year + "-"+pad(month+1) let drafts = Draft.query(qDate, "inbox", [tag]) let result = drafts.map(a => a.title); let chain = "" if (fDayNum != 0){chain = ">".repeat(fDayNum)+" "} let count = fDayNum getDaysInMonth(month,year).forEach(myFunction); function myFunction(item) { count++ if (item == today) { chain = chain + "! " // } else if (result.includes(item)) } else if (result.some(res => res.includes(item))) { chain = chain + "x " } else { chain = chain + "- " } if (count % 7 === 0) { chain = chain + "\n" } } // alert(chain) if (chain != "") { msgbox("chain", chain); }
Options
-
After Success Default Notification Error Log Level Error
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.