Folder Templates, Obsidian Sync and Obsidian being open on two Machines #1096
-
(I thougt I'd start this as a discussion first, before filing an issue. Maybe there is a solution?!) My Setup is as follows:
The problem I run into: When creating a new note in my inbox folder the folder template gets triggered twice:
The reason, I Suspect, is that the file, upon being created, gets synced as an empty file to the unused machine, where it triggers the folder template, while at same time on the currently used machine it also triggers the folder template. When the file is being synced back to the currently used machine, Obsidian merges the files - but since the templates include a timestamp - they are both not exactly the same leading to a duplication of the templates content. Is there a way around that? I would assume that if Obsidian sync would wait slightly longer, that it would sync the contents of the file, therefore leading to the desired outcome. Another kinda funny workaround is to create the file let it sync back and forth and let the idle machine apply the template to the new file. But that is kinda slow and it happens that only of the machines is actually running. What to do? 😅 |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 4 replies
-
Some options I can think of:
There is no way to tell Obsidian Sync to wait longer unfortunately. There's not an easy way to fix this in Templater since Templater is listening to the "file created" event, the file has already been created and started syncing before Templater can do anything to stop it from syncing, assuming there was a way to prevent a file from syncing. TLDR this is a symptom of how Obsidian Sync works, and I don't think there's anything that can be done on the Templater side to resolve this. |
Beta Was this translation helpful? Give feedback.
-
@Zachatoo Yeah, that's what I thought. I would not be against closing Obsidian on the inactive computer, but it's error prone, because there is a human involved. There really should be a plugin or an affordance in Obsidian itself, that differentiates the currently active instance. Alas, there is no good way to prevent this from happening. Just what I thought. Thanks for thinking it through for me! |
Beta Was this translation helpful? Give feedback.
-
<%* app.internalPlugins.getPluginById('sync').disable()-%> at the beginning of a template and <%* app.internalPlugins.getPluginById('sync').enable() -%> at the end often intercepts the sync (not 100%) and allows the template to complete before syncing. |
Beta Was this translation helpful? Give feedback.
-
I would suggest hoisting the sync disable/enable logic into Templater itself. |
Beta Was this translation helpful? Give feedback.
-
I found this solution for myself. You can refine the script to filter out a folder, a path or a filename like in this example. Prevents Templater from cannibalizing templates during sync. <%*
if(tp.file.title === "TITLE OF YOUR FILE") {
throw(new Error("Aborting Templater because it is cannibalizing it's own template (likely due to Obsidian Sync to a new device)"));
}
%> I have a longer writeup and some additional examples here: https://excalidraw-obsidian.online/Hobbies/Excalidraw+Blog/WIKI/07+Developer+Docs/Obsidian+Templater+Tricks#Templater+Cannibalizes+Templates+with+Obsidian+Sync |
Beta Was this translation helpful? Give feedback.
<%* app.internalPlugins.getPluginById('sync').disable()-%> at the beginning of a template and <%* app.internalPlugins.getPluginById('sync').enable() -%> at the end often intercepts the sync (not 100%) and allows the template to complete before syncing.