I have a command line utility, let's called as: produce_image. So i can do the following in the Terminal:

$ produce_image > some.jpg
$ open some.jpg #opens Preview.app

also, I have ImageMagick installed and Xqartz too, so I can do the following:

$ produce_image | display #the display is a command from ImageMagick suite

The above opens an X11 window with the image.

Is possible achieve such image-view as with display also with Preview.app? e.g. looking for something like:

$ produce_image | Preview.app #of course, this isn't working
$ produce_image | /Applications/Preview.app/Contents/MacOS/Preview #nor this

Is possible preview the image with Preview.app without using intermediate file?

Ps: of course, I can create a command such osxdisplay

tmpfile=$(mktemp /tmp/foobar.XXXXXX)
cat - > "$tmpfile"
open "$tmpfile"
rm -f $tmpfile

and use it as

produce_image | osxdisplay

But the merit of the question is about opening images from a shell pipe without intermediate files.

2 Answers 2



produce_image | open -a Preview.app -f

(To be honest, I was quite surprised to learn that this works)

  • GREAT! Working! THANX! :) (Where is this documented?)
    – clt60
    Mar 9, 2015 at 16:43
  • I had a look at man open and then went to see whether -f also works for non-text documents. Tara!
    – nohillside
    Mar 9, 2015 at 16:44
  • I'm simply blind! :( Somewhat missed the _ -f* Reads input from standard input and opens the results in the default text editor_ part. Thank again, you're THE Great!
    – clt60
    Mar 9, 2015 at 16:46
  • is there any way to do the same trick for HTML stream?
    – A B
    Feb 23, 2016 at 1:28
  • @ab If you have a different question, feel free to ask it using the Ask Question button at the top right. Include a link to this question if it helps provide context. Also, please explain what you mean by "HTML stream".
    – nohillside
    Feb 23, 2016 at 5:59

This displays image data from STDIN in the terminal in iTerm 2 (https://www.iterm2.com/documentation-images.html):

cat file.png|printf "\e]1337;File=inline=1:$(base64)\a\n"

The function below displays one or more images in the terminal.

ima(){ local f;for f;do printf "\e]1337;File=inline=1:$(if [[ $f = *://* ]];then curl -Ls "$f";else cat -- "$f";fi|base64)\a\n";done;}

To display images at a maximum height of 20 rows, add ;height=20.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .