Automatic file encryption/decryption: detect file is closed in Mate/Gnome application

1

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.

Queeq

Posted 2013-02-11T07:01:30.253

Reputation: 166

Answers

1

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.

iain

Posted 2013-02-11T07:01:30.253

Reputation: 121