NB - If there are
any further questions about this answer please comment.
UPDATE
There's nothing wrong with the other answers, this one leverages a system command to convert the text file to a compatible filetype for Preview (i.e. PDF).
Given a sample file you can run:
cupsfilter info.txt > info.pdf
(to hide the debug output use cupsfilter info.txt > info.pdf 2> /dev/null
)
After which one may apply the original answer to open the new info.pdf
file in Preview. You can learn more by running man cupsfilter
. I believe this just exposes the basic Save As PDF functionality that exists in the CUPS print system.
(Source)
Additionally
As noted in the comments one can simply pipe the command to open a file directly into Preview. This worked for me:
cupsfilter info.txt 2> /dev/null | open -f -a Preview
(Original Answer)
To open a supported Preview file from Terminal, such as pdf, png, jpg, gif, tiff, bmp:
open -a Preview <nameOfSupportedFileType>
So for example:
open -a Preview [email protected]
Opens the png from the current folder in Preview.
open -a Preview photo.jpg
works for me, it opens the image in Preview.