Skip to content

Instantly share code, notes, and snippets.

@kherge
Created November 9, 2025 05:29
Show Gist options
  • Select an option

  • Save kherge/e8f89d16657e1404954a13369dbb0fc8 to your computer and use it in GitHub Desktop.

Select an option

Save kherge/e8f89d16657e1404954a13369dbb0fc8 to your computer and use it in GitHub Desktop.
Obsidian: Create Child

Create Child

This QuickAdd script will use the name of the active note as a folder name, and create a new note in the folder.

const SETTING = {
ALIAS: "Use Alias",
PROMPT: "Prompt for Title",
PROPERTY: "Parent Property",
TEMPLATE: "Template",
TITLE: "Default Title",
};
const WAIT = 1000;
async function createChild({ quickAddApi }, settings) {
const file = app.workspace.getActiveFile();
if (!file) {
throw new Error("No active file found.");
}
const parent = (() => {
if (settings[SETTING.ALIAS]) {
const cache = app.metadataCache.getFileCache(file);
if (cache?.frontmatter?.aliases) {
return `[[${file.basename}|${cache.frontmatter.aliases[0]}]]`;
}
}
return `[[${file.basename}]]`;
})();
if (settings[SETTING.PROMPT]) {
settings[SETTING.TITLE] = await quickAddApi.inputPrompt(
"Note title:",
settings[SETTING.TITLE],
settings[SETTING.TITLE]
);
}
const parentFolder = file.path.replace(/\..+$/, "");
const childFile = await app.vault.create(`${parentFolder}/${settings[SETTING.TITLE]}.md`, "");
await new Promise((resolve) => {
console.info(`Waiting ${WAIT}ms to ensure Templater does its thing...`);
setTimeout(resolve, WAIT);
});
await app.workspace.getLeaf("tab").openFile(childFile);
await app.fileManager.processFrontMatter(
childFile,
(frontmatter) => {
frontmatter[settings[SETTING.PROPERTY]] = parent;
}
);
}
module.exports = {
entry: createChild,
settings: {
name: "Create Child",
author: "Kevin Herrera",
options: {
[SETTING.ALIAS]: {
defaultValue: true,
description: "Use the first alias of the parent note, if it exists?",
type: "checkbox",
},
[SETTING.PROMPT]: {
defaultValue: false,
description: "Prompt for the title of the new note?",
type: "checkbox",
},
[SETTING.PROPERTY]: {
defaultValue: "parent",
description: "The name of the parent property in the new child note.",
type: "text",
},
[SETTING.TITLE]: {
defaultValue: "Untitled",
description: "The default title for the new note.",
type: "text",
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment