Skip to content

Instantly share code, notes, and snippets.

Last active September 26, 2022 10:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Adds command to ribbon and command palette to open a given file
// updated: 2022-09-26
// Script adds a Command Palette command to open a file
// Install:
// 1. Add this text to a markdown file in your Templater "templates" folder
// 2. In templater settings, add the file you created in step 1 to the Startup section of Templater Settings
// 3. Customize the variables homepagePath and comanndTitle to suit your own needs
// 4. Restart Obisidan. Now the command should be available in the command palette
// Customizing:
// pagePath Full path to the Markdown file to open
// commandTitle Text that is displayed in the Command Palette
// commandID Unique ID for this command. All command palette commands in Obsidian need to have a unique ID
// iconID Icon id name from list of valid IDs. List available at:
(async () => {
const pagePath = "Dashboard/00-Home";
const commandTitle = "Open TFT Hacker Dashboard";
const commandID = "open-home-page";
const iconID = "home";
openFile = (filePath)=> {
const file = app.vault.getAbstractFileByPath(filePath);
const activeLeaf = app.workspace.getActiveViewOfType(tp.obsidian.MarkdownView)?.leaf;
if(app.workspace.getActiveFile()==null || activeLeaf===undefined)
id: commandID,
icon: iconID,
name: commandTitle,
mobileOnly: false,
callback: async ()=> openFile(pagePath)
app.workspace.leftRibbon.addRibbonActionButton(iconID, commandTitle, async ()=> openFile(pagePath));
// app.workspace.leftRibbon.addRibbonActionButton(iconID, commandTitle, async ()=> console.log(app.workspace.getActiveViewOfType(tp.obsidian.MarkdownView).leaf));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment