Hello,
I’m experiencing an issue with a QuickAdd macro that uses a JavaScript script to get the active file path and then appends a Templater template to that file.
Setup:
- QuickAdd Macro: InsertScr
- JavaScript Script:
module.exports = async (params) => {
const { app } = params;
const activeFile = app.workspace.getActiveFile();
if (activeFile) {
console.log("Active file path:", activeFile.path); // Add this line
return activeFile.path;
} else {
console.log("No active file found."); // Add this line
return null;
}
};
* Templater Template Choice:
* Template: \[[Update Title Header Template]]
* File path: `{{MACRO:InsertScr}}`
* Append to file: On, Append at bottom
*
- Templater Template:
- The template simply checks if the Title property is empty if so it prompts for one and then writes to the property. It then adds or changes the 1st header to match the Title property.
Problem:
When I run the macro, it seems to enter an infinite loop. The active file path is repeatedly logged to the console, and the numbers to the left of the console logs rapidly increase. This causes Obsidian to become unresponsive.
Troubleshooting Steps:
- I removed the Templater Template Choice from the macro and ran only the JavaScript script. The script executed correctly, and the file path was logged to the console once, without any looping.
- I have also tested the templater template by itself and it functions correctly.
- I have also had issues with QuickAdd locking up while editing the Template choice. I originally added the scriot name in the {{}} then tried to change it.When I tried editing it Obsidian locked up. I had to cut and paste the whole thing at once to alter it.
Environment:
- Obsidian version: 1.8.7 (191)
- QuickAdd version: 1.13.0
- Templater version: 2.10.0
I’m not sure what’s causing this loop, and I would appreciate any assistance in resolving this issue.
Thank you.
jjquin