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?
Let say you have
If you are using
Open your file.
Now find that process ID (PID) using this command:
Or if you don't want to specify full name, use application name:
Here "22291" is the PID of
To list all opened files by this PID we will use command
Finally, to get only the file location, use this:
If you are interesting what is this magical n means, here is quote from man about
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.