GithubHelp home page GithubHelp logo

obsidian-file-trigger's Introduction

Obsidian File Trigger

Just a simple plugin to trigger a specific obsidian command on a specific file changes.

The exemple works along with APIRequest Obsidian plugin but can maybe used somewhere else.

Why

I wasn't able to fulfill my use case on Commander plugin so here is mine.

My use case is as follow:

  • I want to read my documents every time a specific file change
  • I am able to read my documents through Obsidian API plugin or simply by reading it through SMB
  • The only problem I had is in terms of optimisation because I needed to check every N times if the file has changed
  • This could be optimized by calling a trigger

More specifically, I am using NodeRED which give the ability to provide an API on the fly. But you could also imagine creating a custom API with anything and just catch the event. For the command, I am using APIRequest Obsidian plugin to have the ability to call the plugin. Normally, this APIRequest plugin is more to "insert" information from the request in a page but I am making him bug on result (with a non-JSON response) so it doesn't write anything but call the API anyway. Which is a little workaround because I don't time yet and felt like calling a command is more flexible.

Probably it would be better to create a 2nd plugin that just add the desired complete simple API call without writing anything.

Other possible use cases.

How it Works

Realllly simple

  1. Register to modification event
this.registerEvent(this.app.vault.on('modify', (file) => {
	this.handler.executeCommandOnFileChange(file, this.app.commands);
}));
  1. Prevent spamming with time
  2. Then execute the command on trigger
executeCommandOnFileChange(file, commands)
{
	const currentTime = Date.now();
	
	if (currentTime - this.lastUpdateTime > (this.debounce_time * 1000)) 
	{
	console.log(`File content of ${file.path} has changed.`);
	
	// Execute the command
	commands.executeCommandById(this.command);
}

over

obsidian-file-trigger's People

Contributors

blondwolf avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.