I made a fix for this. In the following example, we will remove all the excalidraw drawings that are not linked by another note.
Make a note with the title “Delete excalidraw orphans” and the following body:
```dataviewjs
dv.list(dv.pages().file.where(f => f.name.startsWith("Drawing ") && f.name.endsWith("excalidraw")).where(f => f.inlinks == 0 && f.outlinks == 0).path.map(path => "<%+ tp.user.delete_file({FILE_TO_REMOVE:'"+path+"'}) %>"))
\`\`\`
Make a user command using (python in my case) that will delete the files:
#!/usr/bin/env python3
import os
if os.name == 'nt':
vault_root_dir = "D:/GOOGLE DRIVE/OBSIDIAN/NOTES"
else:
exit
os.remove(os.path.join(vault_root_dir, os.environ['FILE_TO_REMOVE']))
Just for reference, my user command in the templater config is:
c:/python39/python.exe "D:/GOOGLE DRIVE/OBSIDIAN/NOTES/💎 OBSIDIAN/SCRIPTS/delete_file_by_path.py"
Now whenever you render the note, your orphan excalidraw drawings will be autoremoved.
Now I would like to run this as a single command instead of having to render the note so I can put it fully into a template (So this can be called via the templates menu instead of having to go to the note and render it).
Hopefully someone here knows how to do that 