Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a bash script to automatically decrypt file for editing and encrypt it back after file is closed. File type could be any: plain-text, office document, etc. I am on Linux Mint with Mate.

I'm stuck: can't reliably detect if file was closed in application so that script can proceed to encrypting it back and removing decrypted version.

The first version of the script simply used vim with text files. Script was calling it directly and hadn't been going any further until vim was closed. Now as I want to be able to do so with other files, I tried the following things:

xdg-open: exits immediately after calling the application associated with file type. Thus script continues and does no good.

xdg-open's modified function for calling an associated app: runs it inside the current script so now I see program exit. Works only if the application hasn't been running already. If it has, then new process is finished and script continues.

So what I am trying to do now is to watch somehow that file was closed in already running application. Currently experimenting with pluma/gedit and inotifywait. It doesn't work either - instantly after file was opened it detects CLOSE_NOWRITE,CLOSE event.

Is it at all possible to detect this without specific hooks for different applications? Possibly some X hooks?

Thank you.

share|improve this question

No, there are no X hooks for something like this. You would need to do something specific for each application as they will all handle file access differently from each other.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .