# How to delete linked images when the MD is deleted?

**URL:** https://discourse.devontechnologies.com/t/how-to-delete-linked-images-when-the-md-is-deleted/83252
**Category:** DEVONthink
**Created:** [April 26, 2025, 12:33am UTC](https://discourse.devontechnologies.com/t/how-to-delete-linked-images-when-the-md-is-deleted/83252 "2025-04-26T00:33:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![TonyLim](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/t/5e9695/32.png) [@TonyLim](https://discourse.devontechnologies.com/u/TonyLim)
#### Post date: [April 26, 2025, 12:33am UTC](https://discourse.devontechnologies.com/t/how-to-delete-linked-images-when-the-md-is-deleted/83252/1 "2025-04-26T00:33:28Z")

</div>

When we delete a document with linked annotation, both the document and the annotation are deleted (to be exact, moved to the trash).

How can we do the same for MD document with linked images? How can we have the document and the linked images all move to trash when we delete the MD document.

I have used the below Smart Rule script to move the linked images with the MD document when the MD document is move to a new database. We have “On Moving” trigger/action for that.

> [@Markdown and store image](https://discourse.devontechnologies.com/t/markdown-and-store-image/67291/16):
>
> This Smart Rule script moves linked images to the record’s new database. It’s important that you set e.g. /Assets in preferences, see below. It won’t work if there’s no slash. What The script checks whether an image is also linked in other records whether there’s already an identical image in the new database’s Assets group (“identical image” means an image that would be a duplicate if both images shared a database) Depending on these checks different things happen: If only 1 record li…

I know we do not have “On Deleting” trigger/action. But if we can do that for linked annotation, we should be able to do it with linked images, right?

When we delete a MD document or any document, it is moved to the trash. Can I use “On Moving” and to check that is is moved to trash? Is trash a special location and database that we can identify in scripting.

Or any other methods?

---

<div class="post-metadata">

### Author: ![Stephen\_C](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/stephen_c/32/8107_2.png) [@Stephen\_C](https://discourse.devontechnologies.com/u/Stephen_C)
#### Post date: [April 26, 2025, 5:02am UTC](https://discourse.devontechnologies.com/t/how-to-delete-linked-images-when-the-md-is-deleted/83252/2 "2025-04-26T05:02:11Z")

</div>

> [@TonyLim](#):
>
> Or any other methods?

You can use a smart group similar to this to find unlinked images:

 ![Unlinked](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/c/9/c9f933168c4fd4c000488bca6893594800959f71.png)

Stephen

---

<div class="post-metadata">

### Author: ![TonyLim](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/t/5e9695/32.png) [@TonyLim](https://discourse.devontechnologies.com/u/TonyLim)
#### Post date: [April 26, 2025, 8:34am UTC](https://discourse.devontechnologies.com/t/how-to-delete-linked-images-when-the-md-is-deleted/83252/3 "2025-04-26T08:34:27Z")

</div>

Thanks. This is what I am doing now. This requires manual effort.

It also select those stand alone image, with no link from other document.

Since I am able to move the linked images with MD document, I am looking for the next step (if possible) to auto delete the linked images with the deleted MD document.
