throw new Error('testing mode!'); // Comment this out
const vault = app.vault;
const name = dv.current().file.name;
const swapToDaily = (tries) => () => {
const leaves = [];
for (const leaf of app.workspace.getLeavesOfType('markdown')) {
if (leaf.getDisplayText() === name) {
leaves.push(leaf);
}
}
if (leaves.length === 0) {
if (tries > 0) {
window.setTimeout(swapToDaily(tries-1), 100);
} else {
dv.paragraph('Couldn\'t swap to daily note!');
}
} else {
// MAKE SURE THIS MATCHES YOUR DAILY NOTE SETUP!
const path = `06 - Periodic/Daily/${moment().format("YYYY-MM-DD")}.md`;
if (!vault.getFileByPath(path)) vault.create(path, "");
for (let leaf of leaves) {
leaf.openFile(vault.getFileByPath(path), { active: false });
leaf.setPinned(true);
}
}
};
window.setTimeout(swapToDaily(20), 100);
Last active
September 16, 2024 21:16
-
-
Save NatKarmios/b93f7b3f7f5d046f33f4c0f671c78fa2 to your computer and use it in GitHub Desktop.
Obsidian: redirect to daily note (for workspaces)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## *Redirecting to daily note…* | |
| ```dataviewjs | |
| throw new Error('testing mode!'); // Comment this out | |
| const vault = app.vault; | |
| const name = dv.current().file.name; | |
| const swapToDaily = (tries) => () => { | |
| const leaves = []; | |
| for (const leaf of app.workspace.getLeavesOfType('markdown')) { | |
| if (leaf.getDisplayText() === name) { | |
| leaves.push(leaf); | |
| } | |
| } | |
| if (leaves.length === 0) { | |
| if (tries > 0) { | |
| window.setTimeout(swapToDaily(tries-1), 100); | |
| } else { | |
| dv.paragraph('Couldn\'t swap to daily note!'); | |
| } | |
| } else { | |
| // MAKE SURE THIS MATCHES YOUR DAILY NOTE SETUP! | |
| const path = `06 - Periodic/Daily/${moment().format("YYYY-MM-DD")}.md`; | |
| if (!vault.getFileByPath(path)) vault.create(path, ""); | |
| for (let leaf of leaves) { | |
| leaf.openFile(vault.getFileByPath(path), { active: false }); | |
| leaf.setPinned(true); | |
| } | |
| } | |
| }; | |
| window.setTimeout(swapToDaily(20), 100); | |
| ``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment