Zend certified PHP/Magento developer

How do I automatically save a KeePass entry attachment at unlock / delete it at lock

When I unlock my database, I’d like to be able to save an attached file from a particular KeePass entry to a particular location on my local drive… then delete that file when the database is locked or closed so that it’s not available when my database is locked (some tools need secrets in files, but I only want that available when I’ve got my database unlocked).

I thought I remembered something like that in the past, but after a few days of searching documentation, I cannot find a way to do it (or remember the situation/search that allowed me to think it existed in the past).

I had hoped there was a Trigger with action setup: I can see a Trigger for opened database, but none for closed; and I cannot see an action that saves attachments.

Or, if not that, is there an existing plugin that does that? (Or can such a thing be done in the KPScript scripting plugin? if so, any hints as to which commands I should start researching?)