3

From Nautilus, when I select several PDF documents and press Enter, they are all opened, but in an apparently random order. What is determining the order in which these documents are being opened? Is there a way to open them in the order they appear in Nautilus?

The filenames are enumerated 1 to 7, and the dates of last change also follow that order. But when they're all opened, the window on top might be file 4, file 5 next, then file 2, file 7, etc.

2 Answers2

2

They're open in parallel. nautilus will spawn as many processes (the order doesn't really matter here) and each of those processes will execute your PDF viewer with one of the files as arguments.

All those PDF viewers will work independently, load shared libraries, open their own PDF files, connect to the X server and at some point ask the X server to display a Window. Which one will do that first you have no control on.

To guarantee the order, you'd need cooperation from the Windows manager. You'd need nautilus to ask the Window manager to tell it when the window for the first PDF viewer has popped up before running the next one.

Doing that reliably for any application is not easy. nautilus only knows the pid of the process it spawned to execute the PDF viewer. Not all applications tell the Window manager their pid, and if they do, it may very well be the pid of a child of the process spawned by nautilus (like in the case of a shell script), or it may very well not create a window at all...

1

If it isn't the order in which the files have been selected in Nautilus, I assume the order could either be determined by the physical order of the entries in the directory (check with ls -lU) or the date of the files (ls -lt).

But if the order isn't deterministic (differs with each try) it may just be the time the viewer process(es) need to open, read and render the content, depending on process and I/O schedulers.

To force a deterministic order you could either change the physical order/file time if that's the determining factor. Or create a script that does it, taking the file list from Nautilus and using sort, for and perhaps sleep or some kind of wait-for-process-started mechanism, and add that as alternative to the applications provided by Nautilus for that MIME type(s). The second option is probably more reliable.

Murphy
  • 2,649