June 20 2023
another banger alfred workflow

Writing

Code
Another Alfred banger. This time I'm appending to my weekly note > day of the week > events | thoughts | todo heading. It's basically the best thing ever to an organization and journaling nerd like me.
Example of thoughts pushed today (look at the time stamp!)

Alfred



Python
import sys
import os
import datetime
import argparse
from pathlib import Path
# https://chat.openai.com/share/3e2173cd-b2da-4ae8-8dff-4d1ebde65fdd <- how this is made
append_to = os.getenv("append_to")
query = os.getenv("value")
# Get the day of the week
now = datetime.datetime.now()
day_of_week = now.strftime('%A').lower()
time_string = now.strftime('%H:%M:%S')
# Define the path of the Weekly_Folder
Weekly_Folder = Path("{YOUR_WEEKLY_FOLDER_PATH}")
# Get the most recent file in the Weekly_Folder
most_recent_file = max(Weekly_Folder.glob('*'), key=os.path.getctime)
# Define the section to append to based on the input category
if append_to == "todo":
section = "### todo/" + day_of_week
query = "- [ ] (" + time_string + ") " + query
elif append_to == "events":
section = "#### events/" + day_of_week
query = "(" + time_string + ") " + query
elif append_to == "thoughts":
section = "#### thoughts/" + day_of_week
query = "(" + time_string + ") " + query
else:
sys.stderr.write("Invalid category. Please choose either 'todo', 'events', or 'thoughts'.")
exit()
# Read the file
with open(most_recent_file, 'r+') as file:
lines = file.readlines()
# Find the section and append the string_to_append
start_append = False
for i, line in enumerate(lines):
if line.strip() == section:
# Start appending after the section
start_append = True
elif start_append and (line.startswith("###") or line.startswith("####")):
# Stop appending if we find another heading at the same or higher level
lines.insert(i, query + '\n\n')
break
else:
if start_append:
# If the section was the last one, append at the end of the file
lines.append(query + '\n\n')
else:
print(f"Could not find the section: {section}")
exit()
# Write the modified lines back to the file
file.seek(0)
file.write(''.join(lines))
file.truncate()
sys.stderr.write(f"Successfully appended string to the {append_to} section on {day_of_week}.")
Obsidian Weekly Template
## Commitments
### todo/sunday
#### events/sunday
#### thoughts/sunday
### todo/monday
#### events/monday
#### thoughts/monday
### todo/tuesday
#### events/tuesday
#### thoughts/tuesday
### todo/wednesday
#### events/wednesday
#### thoughts/wednesday
### todo/thursday
#### events/thursday
#### thoughts/thursday
### todo/friday
#### events/friday
#### thoughts/friday
### todo/saturday
#### events/saturday
#### thoughts/saturday
bramadams.dev is a reader-supported published Zettelkasten. Both free and paid subscriptions are available. If you want to support my work, the best way is by taking out a paid subscription.