I want to write a Bash script which will be "watching" some application. As soon as an attempt is made to close/terminate this application, the script will try to stop that termination operation for a few milliseconds, do some stuff and then terminate the application.
I am using Okular to read PDF files and annotate them. But the annotations are saved only in the Okular's docdata. However, if you save the file by using "Save As", the annotations are saved in the PDF file itself.
What I am trying to do is to intercept user's attempt to close Okular by clicking the "x" button on the window, and "Save as" the okular file, replacing the original, and then close the application.
This is meant to be a dirty hack to save annotations in PDF file, as this functionality is not provided in Linux by any good PDF "reader" (please don't name libreoffice or gimp, they're not readers).