I have opened a PDF file with the document viewer from the GUI. Is there any way to get the path of this file in a terminal/script?
To list all files opened by this PID we will use the
Next we'll grep only for pdfs and discard the irrelevant n at start of line:
Finally to combine everything in one bash line:
This one-liner was inspired from the answer of terdon which is also very interesting in the way it solves the same problem.
If you are interested in what n in
Another approach would be something like
In general, whenever you want to search fro a process,
So, the for loop will run
You don't need to specify even the filename of the pdf opened through Document Viewer. This below command will display the paths of all the pdf files opened through Document Viewer.
But all the credit goes to @Corp.