Skip to content

Instantly share code, notes, and snippets.

@shiopon01
Created October 6, 2021 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiopon01/9a35202fca67a93f4d80f6de31235393 to your computer and use it in GitHub Desktop.
Save shiopon01/9a35202fca67a93f4d80f6de31235393 to your computer and use it in GitHub Desktop.
Obsidian Templaterを使用して指定フォルダ内に連番のファイルを作成する

<%* const title = await tp.system.prompt("Enter title"); if (!title) { return; } const inbox = "Inbox/Inbox.md"; const inboxFile = this.app.vault.getAbstractFileByPath(inbox); const inboxContent = await this.app.vault.read(inboxFile); const nextNo = String(Number(inboxContent) + 1).padStart(4, "0");

const filePath = Inbox/${nextNo + " " + title}.md; if (tp.file.exists(title)) { new Notice(Error: ${filePath} is already existed.); return; }

const date = tp.date.now("YYYY-MM-DD"); const noteBody = `--- date: ${date} aliases: [] tags: " #${tp.date.now("YYYY-MM-DD")} #Inbox "

${title}

${tp.file.cursor()}`;

const createdFile = await app.vault.create(filePath, noteBody); await this.app.vault.modify(inboxFile, nextNo); app.workspace.openLinkText("", createdFile.path, true); %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment