I have about 43 files opened in the preview, however, when I run lsof -c Preview
, I only get a fraction of those (i.e. 8 files) which are currently opened.
This is the same output I get when using the Activity Monitor, but I would like to save the complete list of opened files so that I could reopen this list of files later on.
I have found some tips on how to retrieve the list of current files opened in this link.
Does anyone have a hint of what may be happening? Another solution that would be useful is to retrieve the list of files which were opened in the last Preview section.
EDIT:
As commented by D. A. Vincent, it is possible that the files are closed after loaded to memory. If it is possible to make a watcher of the files opened by preview, and log them to a file, this would be an appropriate solution as well. Especially if this watcher thread could be launched when user login or OS starts.
Best Answer
Here's an applescript solution. This should give you a complete list of open files (including the full path) in the preview app.
Also, if any AppleScript gurus come across this answer, I'd be grateful for any constructive criticism you have to offer. :)
This will print the current date followed by a list of every document open in Preview. If you'd rather omit the date just remove the line:
Be sure to fill in the correct information on the line:
If you want to add a date stamp to your filenames, just put the following lines under the
tell application "Finder"
blockThe terminal
date
command has many different formats available. To read about the different options available, open your terminal and typeman strftime
.After playing around a little more I realize this script can simplified even further. This is a more streamlined version that avoids some unnecessary steps from the original. But the result is the same either way.
For ease of use, you can save this script as an Automator service to use while working in any application. To do that just open Automator - then from the File menu select New or ⌘N from the keyboard. Then select Service from the choices shown. When the document opens, select Utilities in the far left column. Then Select Run AppleScript in the column to the right of that. Paste this script into the box that appears. In the drop down choices near the top of the page, select Service receives no input and in any application. Then just pick and name, save the file and you should have a service available to use anytime in the services menu.
Update
Here is a way to read and open the list of files we just created. This will allow you to pick and choose which files you want to open without having to open every file in the list if you don't want to.
Hope it helps. Let me know if you have any problems.