Skip to content

Additional Gallery items

Chris Gurney edited this page Jun 16, 2026 · 58 revisions

This page provides more examples of items to add to your toolbars that make use of the clipboard, and reading/writing files within your vault.

These items were previously included in the Gallery but have been moved here because they require access to external resources or vault content. Review the scripts before adding these items to a toolbar.

Instructions

Use the Add this item button to add it to Obsidian, or:

  1. Create a JavaScript type item (unless otherwise noted)
  2. Select Evaluate JavaScript
  3. Enter the script for the selected item, below

List of items

Clipboard

Item Description
Copy to clipboard Copies the selected text to the clipboard.
Cut to clipboard Cuts the selected text to the clipboard.
Paste from clipboard Inserts clipboard text at the cursor position in the editor.
Copy link to block Copies a wiki link to the current block (based on block ID or line metadata).
Copy note content Copies the note body to the clipboard, excluding frontmatter.
Paste external embed Pastes an embedded external link. Checks the clipboard for a link first, otherwise prompts for a link.

Files

Item Description
Append text to file Prompts for input text and appends it to a specified file in the vault.
Display file list Displays a list of files from a folder (defaults to current note folder, excludes current file). Requires Dataview.
Open file in new tab Opens the selected file in a new tab.

Note Toolbar

Item Description
Backup Note Toolbar data Creates a timestamped backup of the plugin’s data.json configuration file in the vault.
Export all toolbars to callouts Exports all toolbars into a markdown file formatted as callouts for sharing or reuse.

Clipboard

Move note text to and from the clipboard, for use in other applications.

Copy to clipboard

Copies the selected text to the clipboard.

const e = ntb.app.workspace.activeLeaf.view?.editor;
try { 
  await activeWindow.navigator.clipboard.writeText(e.getSelection());
  e?.focus(); 
} 
catch (e) { 
  console.error(e); 
  new Notice('Error: Please check console for details'); 
}

Cut to clipboard

Cuts the selected text to the clipboard.

const e = ntb.app.workspace.activeLeaf.view?.editor;
try { 
  await activeWindow.navigator.clipboard.writeText(e.getSelection()); 
  e.replaceSelection(''); 
  e?.focus(); 
} 
catch (e) { 
  console.error(e); 
  new Notice('Error: Please check console for details'); 
}

Paste from clipboard

Pastes the text from the clipboard into your note.

const e = ntb.app.workspace.activeLeaf.view?.editor;
try { 
  let rs = e.replaceSelection;
  let text = await activeWindow.navigator.clipboard.readText();
  if (text) rs.apply(e, [text]); e?.focus();
}
catch (e) { 
  console.error(e);
  new Notice('Error: Please check console for details');
}

Copy link to block

Copies a link to the current block ↗ to the clipboard, if there is one.

const editor = ntb.app.workspace.activeEditor?.editor;
const file = ntb.app.workspace.getActiveFile();
const line = editor?.getCursor().line;

const blockId =
    editor?.getLine(line).match(/\^([\w-]+)/)?.[1] ??
    app.metadataCache.getFileCache(file)?.blocks?.[line]?.id;

if (blockId) {
    window.navigator.clipboard.writeText(`[[${file.path}#^${blockId}]]`);
    new Notice('Copied to clipboard');
}
else {
    new Notice('No block ID found');
}

Copy note content

Copy body of the note to the clipboard, ignoring frontmatter.

const editor = ntb.app.workspace.activeLeaf.view?.editor;
if (!editor) return;

const body = editor
    .getValue()
    .replace(/^---\n[\s\S]*?\n---\n*/, '');

await activeWindow.navigator.clipboard.writeText(body);
new Notice('Copied to clipboard');

Paste external embed

Add an embedded external link. Checks the clipboard for a valid media link first (defined in the list of allowed hosts), otherwise prompts for a link.

let url = '';

try { url = (await activeWindow.navigator.clipboard.readText()).trim(); } catch {}

const allowedHosts = ['youtube'];

const isAllowed = (u) => {
    if (!URL.canParse(u)) return false;
    const host = new URL(u).hostname;
    return allowedHosts.some(h => host.includes(h));
};

if (!isAllowed(url)) {
    url = (await ntb.prompt({ placeholder: 'Paste a supported media URL' })) ?? '';
}

if (isAllowed(url)) ntb.setSelection(`![](${url})`);

Files

Tools for working with files.

Append text to file

Appends the prompted text to a file you specify.

const filePath = 'File.md'; // CHANGE THIS TO ANY FILE

const file = ntb.app.vault.getAbstractFileByPath(filePath);
if (!file) {
    new Notice('File does not exist');
    return;
}

const text = await ntb.prompt({ large: true });
if (!text) return;

const content = await ntb.app.vault.read(file);
await ntb.app.vault.modify(file, `${content}\n\n${text}`);

Open file in new tab

Opens the selected file in a new tab and switches to it.

const file = await ntb.fileSuggester(
  ntb.app.vault.getAllLoadedFiles(),
  {filesonly: true}
);
if (file) {
  const leaf = ntb.app.workspace.getLeaf(true);
  await leaf.openFile(file);
  ntb.app.workspace.setActiveLeaf(leaf, {focus: true});
}

Display file list

🧩 Requires the Dataview ↗ plugin.

Shows a list of files in the specified folder (and subfolders), in the current note. Excludes the current file. Defaults to current folder if folder not provided. Sorts alphabetically.

Instructions

  1. Paste this script into a .js file in your vault.
  2. Create a Dataview type item.
  3. Select Execute JavaScript file.
  4. Enter the script below.
  5. In the Arguments field, enter: fileFolder: "Scripts" where "Scripts" is the name of the folder you want to list files for.
  6. Add a Note Toolbar Output Callout and add its ID under Advanced settings (instructions) to render the output in.
function FileList(input) {
    let fileFolder;

    if (input) {
        ({fileFolder} = input);
    }
    /* if fileFolder is not provided... */
    else {
        /* ...default to the folder of the calling note */
        fileFolder = dv.current().file.folder;
    }
    fileFolder = fileFolder ?? "";

    const files = app.vault.getFiles()
        .filter(file => (fileFolder === ""
            ? !file.path.includes("/")
            : file.path.startsWith(
                fileFolder.endsWith("/") ? fileFolder : fileFolder + "/"))
            && file.path !== dv.current().file.path)
        .sort((a, b) => a.name.localeCompare(b.name));

    dv.paragraph("📂 `" + fileFolder + "`:");
    dv.list(files.map(file => dv.fileLink(file.path)));
}

FileList(input);

Note Toolbar

Backup Note Toolbar data

Copies Note Toolbar's settings (data.json) file into the vault.

const src = `${ntb.app.vault.configDir}/plugins/note-toolbar/data.json`;
const date = new Date().toISOString().slice(0, 10).replace(/-/g, '');
const dest = `note-toolbar-${date}-data.json`;

ntb.app.vault.adapter.read(src).then(data => { 
  ntb.app.vault.adapter.write(dest, data); 
  new Notice(`Created: ${dest}`); 
});

Export all toolbars to callouts

Writes an export file containing all toolbars as callouts.

const toolbars = ntb.getToolbars();
let callouts = '';

for (let toolbar of toolbars) {
    callouts += `## ${toolbar.getName()}\n\n`;
    callouts += await ntb.export(toolbar);
    callouts += '\n';
}

const datestamp = new Date().toISOString().replace(/[:.]/g, '').replace('T', '-').split('Z')[0];
const filename = `TOOLBARS ${datestamp}.md`;
await ntb.app.vault.create(filename, callouts);

new Notice(`Toolbars exported to:\n${filename}`);

Clone this wiki locally