sometimes I insert a screenshot in a markdown document (it is then automatically saved in the assets group) and afterwards I delete it from the markdown document. Is there any possibility to delete those images from the assets group that are not linked to from any markdown document in my database anymore? maybe with a smarrule? or is applescript necessary for doing that?
I don’t think that a smart rule can do that. It can be scripted.
I’d go the other way round: loop over all images in the assets group and check for each of them if it’s referenced in any MD file. If not, delete the image.
But that will not be fast. Why does it bother you to have unreferenced images?
For what it’s worth I use this smart rule to discover any unlinked images I may have in my diary markdown files:
I know it doesn’t delete the images, as you wanted, but that’s not a particularly onerous job once you have found them.
Very nice! I had never even considered that as it’s too easy to narrowly think about text document linking.
I suppose that only works with
x-devonthink-item links, not with something like
assets/screenshot.png though? I just checked one of my images that’s linked to in an MD document that way, and it didn’t display an incoming link. OTOH, an image referred to by an item link showed the incoming link correctly.
So, your solution will help @vinschger if they use item links.
I suspect that is (as usual) a perfectly fair comment—for I’d never tested the rule against anything other than DEVONthink item links because those are what I use exclusively in my diary entries. Thanks for pointing out that pre-requisite.
Indeed. @cgrunenberg would have to assess the feasibility of detecting the non-item link links as outgoing.
Thanks so much to all of you! Currently my imported markdown images are saved in the assets subgroup and linked to as
assets/xyz.png. For telling the truth I am very unsure if I would better use item links in my markdown documents (currently I am not using any third party markdown editor and therefore item links would also work. Would it even be possible to convert the non-item links to item links? do I need scripting for that (no scripting knowledge on my side)?
Yes on both accounts.
Item links presumably preclude external MD editors from displaying the image(s) in preview, and the link doesn’t tell you anything about the image that you’re using (whereas you can use speaking names with
But converting links to item links only to be able to remove unused images seems to be a bit convoluted. You’d have to script the conversion from link to item link, so why not write a script that removes unused images in the first place? And, again: Why are unused images an issue at all?
thank you very much for following-up. I have found a posting here in the forum that allows to convert wikilinks to item-links, but none for non-item links to item links and vice-versa for markdown documents. It’s no tragedy to have unused images in the assets folder, but I do not need/want to preserve unused images, so it’s more comfortable while going through the assets folder to find certain images.