How to auto run shell command when note is created or updated?

Things I have tried

I searched help docs and forum. Have also reviewed several plugin repos on github that can help but not fully solve the problem.

What I’m trying to do

How to auto run shell command when note is created or updated?

The bigger use case is really a sort of one-way convert/export & sync to a local folder based on tags.

Only want certain files that I explicitly tag to be exported. A mini one-way sync for a filtered subset of files.

So…

  • GIVEN
    while writing notes in Obsidian
  • WHEN
    any notes is created or updated
    AND note contains specified tag
  • THEN
    shell command called that converts and exports note to local folder

Am using or have looked at plugins like Auto move, Templater, Shell commands, Pandoc plugin, and more.

Barring one plugin that meets the whole workflow I’m looking for, I am really close to piecing it together just fine with some of the plugins mentioned above:

  • When Note created or updated (<-- Missing Piece)
  • Use Shell Command (or other plugin) to execute shell command to
  • Use pandoc to convert and export note as HTML

The one bit I haven’t figured out yet is how the first step, how to trigger the shell command automatically whenever a note is created or updated?

Is there something simple I am overlooking? Or a plugin that can help here?

Guessing I could cobble together a powershell script outside of Obsidian that watches folders and does this on its own, but that feels like bigtime overkill and would also require running it separately.

Any pointers or tips would be greatly appreciated.

Woohoo – I just found this update in the Shell commands plugin’s git repo: " Events: Execute shell commands automatically when something happens"

Thank you @Jare - this is awesome.

This is in development and would very much solve this problem! Hoping there’s something I can still do in the meantime, but wanted to share this for anyone else who comes across this post.

2 Likes

OK, there’s way more here in the Shell command plugin than I realized. I’m sure now I can find something to meet this need until the specific events I’m interested are working…

1 Like

Hi @mysticmisfit ! This is a nice coincidence, I just started developing these new file related events a few days ago in the plugin. Happy to see that there’s some need for them already! :slightly_smiling_face:

  1. There will be the new File content modified event (as you saw). It will call your shell command every time a file in your vault changes.
  2. You can pass the value of {{tags}} variable to your shell command.
  3. In your PowerShell shell command, have an if condition to check if the passed tags contains the tag you want to control the conversion/exporting. I’m not very familiar with PowerShell (I’m learning :slightly_smiling_face: ), so I don’t know how to make that kind of if statement from the top of my head, but I know it’s possible. An alternative to tags is a YAML frontmatter property. Those can be accessed using {{yaml_value}} variable. It’s your choice, if you like tags more, you can use them, this is just one idea.

If you need further help after the version of Shell commands that will support these new events is released (0.13.0), you can either ask here in this topic or in Q & A discussion category of the Shell commands plugin’s GitHub repository. I can then use some more time to find out a working solution on how to implement the if condition I mentioned above.

3 Likes

Just to give a remark here too, Shell commands 0.13.0 was released a couple of weeks ago, so the File content modified event is now available.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.