Open data from a pipeline in any application

Mar 20, '08 07:30:05AM

Contributed by: boredzo

The open(1) command (man page) provides a -f option, which open's own help says "Reads input from standard input and opens with TextEdit". But, in fact, you can load the data into nearly any application. Simply combine the -f flag with the -a flag:

Of course, the source of the data doesn't have to be curl; it can be any command. Note that the last two examples aren't even textual data: one is an image, and the other is a video file. You aren't limited to text; any data will work. But there is a catch: open will save the file with a .txt extension, regardless of what kind of data it is (it doesn't look). This could confuse some applications that rely on the filename extension to determine what type of document to open it as. Preview works, but I wouldn't count on any other applications without testing them first.

This hint works in 10.4, and should also work in 10.5. I don't know whether it works in any earlier versions of Mac OS X.

Comments (5)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2008031505562229