Skip to content

Instantly share code, notes, and snippets.

@Boettner-eric
Created June 11, 2025 22:37
Show Gist options
  • Save Boettner-eric/d08218aaaeb411c614a98ee6ae4728bd to your computer and use it in GitHub Desktop.
Save Boettner-eric/d08218aaaeb411c614a98ee6ae4728bd to your computer and use it in GitHub Desktop.
Obsidian split week workspace template. Quickly open obsidian to a split week/day view.
const leaves = app.workspace.getLeavesOfType("markdown")
for (const leaf of leaves) {
leaf.detach()
}
const dayFolder = "00 - Daily"
const weeklyFilename = "Week " + tp.date.now("w YYYY") + ".md"
const dailyFilename = tp.date.now("ddd MMM D, YYYY") + ".md"
const weeklyExists = await tp.file.exists(dayFolder + "/" + weeklyFilename)
const dailyExists = await tp.file.exists(dayFolder + "/" + dailyFilename)
// Create files if they don't exist
if (!weeklyExists) {
const weeklyTemplate = tp.file.find_tfile("99 - Database/Templates/Week {{date}} Overview")
await tp.file.create_new(weeklyTemplate, "Week " + tp.date.now("w YYYY"), false, dayFolder)
}
const weeklyFile = app.vault.getAbstractFileByPath(dayFolder + "/" + weeklyFilename)
const dailyFile = app.vault.getAbstractFileByPath(dayFolder + "/" + dailyFilename)
// Open the weekly note in the current pane
await this.app.workspace.getLeaf("tab").openFile(weeklyFile)
const weeklyView = this.app.workspace.activeLeaf.getViewState()
weeklyView.state.mode = 'source'
this.app.workspace.activeLeaf.setViewState(weeklyView)
// Create a new leaf for the daily note
const dailyLeaf = this.app.workspace.getLeaf('split')
if (!dailyExists) {
const dailyTemplate = tp.file.find_tfile("99 - Database/Templates/{{date}}")
await tp.file.create_new(dailyTemplate, tp.date.now("ddd MMM D, YYYY"), true, dayFolder)
} else {
await dailyLeaf.openFile(dailyFile)
}
const dailyView = dailyLeaf.getViewState()
dailyView.state.mode = 'source'
dailyLeaf.setViewState(dailyView)
// Give focus to the daily note
this.app.workspace.setActiveLeaf(dailyLeaf, { focus: true })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment