[SOLVED] Is there a plugin to remind you to also delete the attachments that are in a file?

What I’m trying to do

After realizing that the images that were part of an .md file (as in: had been inserted / attached) were not deleted whenever I deleted the .md file, I thought it would be helpful to have a plugin that:
a) asks if you also want to delete all the attachments associated with the .md file (I realize you may NOT want to do that, if they are used in other .md files or elsewhere)
b) will delete them for you.

Things I have tried

I did search around, in vain, with the words above. In the documentation, here in the forum, on obsidianstats, on the web in general.
Likely I’m not using the right words in my search; I apologize.

I am not aware of any plugin, but you can use bases for this task.

You create a base and filter for you attachments. Depending on your vault structure you can do this by folder or file extensions for example.
Then you also add the filter file.backlinks.isTruthy(). The base will then only show attachemts that are not linked in any note and you can delete them.

i don’t know about others, i use a plugin called pasted image rename and convert. the best thing it does is that when you paste a screenshot, it will ask you to rename it (by default it named after the file) and it convert image from png to webp(reduce size greatly).
i renamed with D for delating screenshots. and delete them later, as the attachment folder is pinned at top of my gallery.
i rarely depend on plugin. i only have 6 plugins.:wink:

Thank you so much for this! I had not looked into bases before, because they scared me and I had no time to learn something new. However, I decided to tackle it for this task. I can use this method to clear out the orphans I have amassed so far, while I consider how to manage it going forward.

I managed to set the filter so all my attachments would show – I have them all in a folder (with some subfolders) called “assets”. (I moved all my notes over from OneNote, hence the subfolders, and the hundreds of files without any more meaningful titles than “exported image xxxxx”.)

That filter shows the correct number of files (617).

When I then add your filter, the number of files shown is down to 581, something is happening. But: it can’t be correct, because 1. I don’t have such a large number of not-linked items in “assets” and 2. I could spot right away those with real names which I know are linked.

Could it be your filter actually shows the ones that are linked?

Sorry my bad.

Yes, you are right, this filter will show any files which are linked in any other file.

You can create a filter group and choose a not filter (Views - Obsidian Help) or you can adjust the formula.

Huh. Now bases scare me even more… I just spent the last two hours reading through the Obsidian Help and around on the web. Before that, I would have thought a simple “isnot” or something would exist. Logically, it shouldn’t be that difficult to ask the opposite of a function.

Then I tried the ! in front of your filter (mentioned as the operator for ‘logical not’) – that significantly lowered the number of results, to 36. However, no idea what it actually did, because all filtered files I checked thus far are actually linked.

Then I tried it the way you mentioned and picked as a new filter (while temporarily deleting yours): file > does not link to > *.md

That did nothing.

Would you mind helping me once more? I’m stuck. :worried:

Is this what you need?

Bases can be a little overwhelming at the beginning.

The filter file.backlinks.isTruthy() should give you all files which are linked in one or more other notes.
You can negate this condition to get file without a linked mention with the following options:

  1. Put a ! in front as you mentioned so !file.backlinks.isTruthy().
  2. Choose the following option for a filter group
  3. Use a different condition, for example file.backlinks.isEmpty() should give the same results.

With one of this filter, the files the base shows should not be linked in another file. You can check this by adding this formula to your base table file.backlinks which will show all files which are linked to your files. This should be empty in your case.

However, using the .backlinksfunction is not automatically refreshed (Bases syntax - Obsidian Help), so it can happen that the base showsincorrect results, but it should be refreshed after a restart of obsidian.

Can you give me an example of attachments which are shown in the base despite having a linked mention ?

YES! Thank you so much!!

I never use the right search terms, apparently. THIS is what I was looking for – I “hacked” the main.js file to also search for pdf – and it worked perfectly. Phew!

Thank you so much for trying to help me. Your explanations will come in handy should I encounter another task that would be suitable for using bases.

For now I’m happy with the (slightly adjusted) recommended plugin.

Once I adjusted my search to limit it to the removal of images, I also found this one here:

I haven’t tested it, just wanted to share, in case someone else needs this.