I want to make a button to copy text I specify to the clipboard

Alternate solution, which I think might be better

Thanks for the details, as it illustrates your use case a lot better. In fact, I would like to point your attention to this thread answer of mine:

It shows an alternate way of handling a similar use case. In this use case, you can write a shorter text, hit the hotkey, and insert the longer text from your snippet collection.

Regarding the error, and possible solution

Regarding your error I reckon it’s due to Obsidian executing all the templater code when you hit either button. Not sure if it’s supposed to do so, or not, but I think that’s what’s happening. So not sure if it’s doable using those buttons that way.

There are some other options, though, and that would be that each button triggers another template, which either holds the text you want copied, or does the copy to clipboard. Something like the following:

```button
name Log
type append template
action Hourly Log Template Note
```
^button-log

The question I would like to ask then though is: Do you really need to push the button? Wouldn’t it be better to just trigger the template to insert stuff directly?

Using hotkeys to trigger templates

It turns out that using Templater you can add shortcuts to the various templates, so I would consider having your various texts as templates, and then connect a hotkey to each template.

This can be done going to Settings > Templater > Template Hotkeys, and then Add new hotkey for template. Find your template after clicking in the box, and then hit the plus icon to select a hotkey to trigger this particular template.

Using a Templater suggester

I’ve not used these myself, but a template in Templater can populate a selection box, where you can choose from a list of values (which you specify). This value can then be processed further, and in your case you just insert it into your text.

In summary

Both of these last solutions allows for the removal of the buttons in your notes (and thusly removes a little bit of clutter), whilst still allowing for easy insert of your various texts.

Still I kind of lean towards the first solution, as that would give you the most flexibility (and reduced clutter overall) to easily insert text based upon some abbreviation/shortcut of your choice.

1 Like