obsidian-execute-code icon indicating copy to clipboard operation
obsidian-execute-code copied to clipboard

[FR] Alternative to just a run button

Open Aetherinox opened this issue 1 year ago • 4 comments

I have some sqlite databases which I'd like to run queries on which can be done via regular commands in terminal.

Was wondering if there's a way to possibly have a particular code block execute when the note is loaded, instead of just by manually pressing the run button.

I'm looking to have the query executed, and return the data back to the note when it's loaded without manual interaction.

Aetherinox avatar Nov 24 '23 08:11 Aetherinox

Hi! Sure, I think that would be possible and wouldn't be that hard to implement. I don't know when I will be able to implement it though

twibiral avatar Nov 24 '23 09:11 twibiral

That's fine. It would just be majorly helpful. I'd like to be able to run queries without manual interaction and would help out a ton.

Could be something as simple as defining a new property in the code block, ie:

```run-code auto
code here
```

Aetherinox avatar Nov 24 '23 11:11 Aetherinox

Quick question, would this be run every time the note is reloaded? In editing and reading view as well? Or instead just when the note is first loaded after the vault is first opened? For example, if it is every time the note is reloaded, enabling a plugin would cause it to run etc. Would that be intended behvaiour?

mayurankv avatar Nov 27 '23 12:11 mayurankv

Hrm.... interesting.

I would say ideally, if possible. Having an option to define that in the code block? That would be super helpful.

Because say with my example, I want to run a terminal / command prompt query which accesses SQLite3. And since Sqlite3 doesn't have any type of impact on performance of the system, I can have it run as many times as I want, and I want the data to be current.

I didn't even think about the editing vs reading mode situation, because I hardly use reading mode. I try to only use plugins that support both, so that I can stay in editing mode but if I need reading mode, it's there.

Initially I was thinking about it running the query as soon as you switch to that particular note in the left side File Explorer frame. Then my query would be automatically ran and the data presented right there on note load.

Aetherinox avatar Nov 27 '23 15:11 Aetherinox