Templater + Sync Overwrite Issue - Workaround!

Greetings all -

Not sure how many others are plagued by this, but I’m running into lots of Sync + Templater issues, with my mobile overwriting edits I’ve made on my laptop, and syncing back to the Templater “code”.

I understand why this occurring - Sync/Obsidian events are just too fast! :sweat_smile:

However, I think I’ve found a workaround using the QuickAdd plugin (which I love for other reasons too).

QuickAdd is based on Templater, so it uses the underlying engine and adds value on top. It allows you to create a command (via command palette) to add a template + so much more like choices and input prompts. You can also use it to create a “Macro”. The Macro is just like it sounds, a bunch of things that run in sequential order, including creating the template.

So, I configured a Macro to

  1. run a script to temporarily disable Sync plugin
  2. make the template (including a prompt to ask me the file name)
  3. enable Sync again.

Seems to be working great after some testing. Hope this can help someone else.

Example of the script files for the Macro:

disableSync.js

module.exports = async (params) => {
  try {
    //disables sync
    await app.internalPlugins.plugins.sync.disable();
    console.log("Sync temporarily disabled to create template");
  } catch {
    //eat it
    console.error("Error in QuickAdd or script. Check Sync plugin.");
  }
};
1 Like