Open several PDFs from Terminal

Preview used to open multiple PDFs launched like this in a single window. But the changed on High Sierra at least, as now it opens each in it's own window. It still opens multiple pictures in a single window, aka open *.jpg

Commented Nov 8, 2018 at 5:20

2 Answers 2

If you want to just open a list of PDFs all at once, you just need to separate the file names (enclosed with quotes) by a space as follows:

open "file1.pdf" "file2.pdf" . "fileN.pdf" 

This will open every PDF specified on one line.

If you want to open every PDF in a particular directory, use the command (simple for/do loop):

for file in /Path_to_Directory/*.pdf; do open "$"; done 

Both of the examples above use the default app associated with the file (Preview). If you want to specify a particular app (maybe you have a different PDF viewer but want to use Preview) use the -a flag and specify the app:

for file in /Path_to_Directory/*.pdf; do open -a Preview.app "$"; done 

Note: Be sure to enclose the variable name in quotes (") to account for spaces and non-printing characters. For example, if you have a file named "My PDF File.pdf", not including the quotes will cause the command to try and open each string ("My", "PDF", and "File") as separate files.

answered Feb 20, 2018 at 19:11 104k 33 33 gold badges 206 206 silver badges 464 464 bronze badges

The first command, due to shell globbing, open "file1.pdf" "file2.pdf" is exactly the same as open file*.pdf`

Commented Nov 8, 2018 at 5:24

The manpage for open in Sierra still says:

 You can specify one or more file names (or pathnames), which are inter- preted relative to the shell or Terminal window's current working direc- tory. For example, the following command would open all Word files in the current working directory: open *.doc Opened applications inherit environment variables just as if you had launched the application directly through its full path. This behavior was also present in Tiger. 

That means your initial approach is usually also the correct one. That is "usually" as in: this open command is buggy (and Preview is buggy, too).

If your PDFs have 'proper' filenames, then all is well and in a directory with 20 PDFs all PDFs will be opened in the manner the manpage promises.

However, if there are 'funny' filenames, legally allowed (or represented differently on the filesystem) on HFS+ but known for being 'difficult' in a shell environment, problems arise.

The globbing function for open is broken. If for example a filename starts with - (minus sign) the next character gets interpreted as another option for the open command. Since there are not many options available for the open command this results often in an error. Spaces in filenames, everything that would need escaping in a normal shell command, seems to be troubling for this command.

Other bugs to observe are that using the option open -a Preview.app does not work as might be expected. Further, it seems that Preview does not respect your preferences whether newly opened docs should all get their own window. Preview opens multiple PDFs with a simple open *.pdf but all those docs are then 'hidden' in the sidebar of a single shared window. You then have to click the triangles to reveal that there are multiple files open now.

A number of files with clean names in a single working directory accessed via open *.pdf with Preview.app set as your default PDF-viewer will open them all (well, I didn't check a probable upper limit on this…)

That leaves now the following options: