twibiral / obsidian-execute-code

Obsidian Plugin to execute code in a note.
MIT License
1.06k stars 67 forks source link

[FR] Alternative to just a run button #307

Open Aetherinox opened 9 months ago

Aetherinox commented 9 months ago

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.

twibiral commented 9 months ago

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

Aetherinox commented 9 months ago

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
mayurankv commented 9 months ago

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?

Aetherinox commented 9 months ago

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.