## Note Refactor Philosophy This is the manual approach to enable that old frontmatter schema are updated correctly in a migration of sorts. For real time occurences, there is a loop that monitors onChange events such that certain permalink characteristics get modified for open editors ## Script-based Approach. - Batch Apply Ubiquitous Note properties - Apply Ubuiqitous Note properties - Initialize OnEdit parameters - created = moment.time - updated = moment.time - edited_seconds = null - word count = f(calculateWordCount) - permalink = f(permalink prompt) - Custom Templating - Philosophy - article schemes (jurisdicts subsequent frontmatter entries which are initialized or removed based on this property) - Examples - Daily Note (calls Daily Note Template) - Gear (calls relevant Gear Template) - Batch apply periodic note properties with periodic-note-refactor - Adjust daily note frontmatter - New notes - Create new notes without date based on `/Daily Note.md` - Existing Notes - Add creation date and update - Benefit - Use Dataview to render the daily note according to this frontmatter attribute so to know what was used that was created, and what was the order of things that were modified, in heading at very bottom called # Creation and # modified in daily note template # Script #wip ## Note Creation Script To programmatically add or update the created and updated timestamps in the YAML frontmatter of all Markdown files within your Obsidian vault, you can utilize the following Python script. This script reads each Markdown file, extracts or adds the YAML frontmatter, and updates the created and updated fields based on the file’s system creation and modification times. **Prerequisites:** 1. **Install Python 3:** Ensure that Python 3 is installed on your system. You can download it from [python.org](https://www.python.org/downloads/). 2. **Install Required Libraries:** This script requires the pyyaml library. Install it using pip: ``` pip install pyyaml ``` **Python Script:** ```python import os import yaml from datetime import datetime def update_frontmatter(file_path): with open(file_path, 'r', encoding='utf-8') as file: content = file.read() # Split frontmatter and content if content.startswith('---'): parts = content.split('---', 2) frontmatter = yaml.safe_load(parts[1]) body = parts[2] else: frontmatter = {} body = content # Get file system timestamps stat = os.stat(file_path) created_time = datetime.fromtimestamp(stat.st_ctime).strftime('%Y-%m-%d %H:%M:%S') modified_time = datetime.fromtimestamp(stat.st_mtime).strftime('%Y-%m-%d %H:%M:%S') # Update frontmatter if 'created' not in frontmatter: frontmatter['created'] = created_time frontmatter['updated'] = modified_time # Reconstruct the file content new_content = f"---\n{yaml.safe_dump(frontmatter)}---\n{body}" with open(file_path, 'w', encoding='utf-8') as file: file.write(new_content) def process_vault(vault_path): for subdir, _, files in os.walk(vault_path): for file in files: if file.endswith('.md'): file_path = os.path.join(subdir, file) update_frontmatter(file_path) print(f"Updated: {file_path}") # Replace with the path to your Obsidian vault vault_path = '/path/to/your/obsidian/vault' process_vault(vault_path) ``` **Instructions:** 1. **Set the Vault Path:** Replace '/path/to/your/obsidian/vault' with the actual path to your Obsidian vault directory. 2. **Run the Script:** Save the script to a .py file and execute it using Python: ``` python script_name.py ``` **Important Considerations:** • **Backup Your Data:** Before running the script, ensure you have a complete backup of your Obsidian vault to prevent any accidental data loss. • **File System Timestamps:** The script uses the file system’s creation (st_ctime) and modification (st_mtime) times. Be aware that these timestamps can be altered by certain actions, such as copying files between different file systems. • **Frontmatter Parsing:** The script assumes that the YAML frontmatter is correctly formatted and located at the beginning of the Markdown files, enclosed by --- delimiters. Ensure that your files adhere to this structure to prevent parsing issues. By running this script, you can efficiently update all your existing Markdown notes with accurate creation and modification timestamps, enhancing your ability to perform date-based queries and organization within Obsidian. ## Template Scripts ### Daily Note ### Gear Template