Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "User Script Hotkeys" in plugin settings, just like "Template hotkeys. #1334

Open
stroiman opened this issue Mar 5, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@stroiman
Copy link

stroiman commented Mar 5, 2024

I have grown REALLY fond of the scripting functionality of templater, and use that to automate quite a lot of mundane tasks.

For example, I keep a log of medicine taken in the frontmatter, but as an array. This gets cumbersome to edit, but a script solves that easily, and Templater is SUPER GREAT FOR THIS. You rock!

But right now in order to actually trigger the script, I need to (as far as I can tell) create a dummy templater note, that I can then trigger using the "Template Hotkeys" configuration.

So the script looks like this

async function addMedicine(tp) {
  const { type, dose, time } = await // .. tp.system.promt calls to get these
  app.fileManager.processFrontMatter(tp.config.target_file, metadata => {
    const log = metadata['medicine-log'] || [];
    metadata['medicine-log'] = [...log, { type, dose, time }];
  })
}
module.exports = addMedicine;

Not I can create templates/add medicine.md

<%*
tp.user.addMedicine(tp)
-%>

And now I can add a hotkey to the templates/add medicine.md file.

This is SUPER COOL, and it solves my problems.

BUT if I didn't need to create this skeleton template to wrap the script, it would be even more awesome.

I tried searching for other Obsidian plugins that allowed me to run adhoc scripts, but I didn't find one. Don't know if I didn't look well enough. But many of the scripts are for creating contents, so having the affinity with templater is helpful for some tasks.

@stroiman stroiman added the enhancement New feature or request label Mar 5, 2024
@stroiman stroiman changed the title Add "User Script Hotkeys", just like "Template hotkeys. Add "User Script Hotkeys" in options, just like "Template hotkeys. Mar 5, 2024
@stroiman stroiman changed the title Add "User Script Hotkeys" in options, just like "Template hotkeys. Add "User Script Hotkeys" in plugin settings, just like "Template hotkeys. Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant