Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Pipe to Safari from stdin' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Pipe to Safari from stdin
Authored by: nxg on Dec 01, '05 12:03:30PM

This sounds extremely nice, but there's something Clever happening which stops it being reliable.

The suggestion by `rspeed' works as expected -- Safari says `Moo' -- but

open -a /Applications/Safari.app -f <file.html

doesn't, when file.html is an XHTML file. Instead, Safari just displays the contents as plain text. And lo and behold, the following

echo "<?xml version='1.0'?><html><body>Moo</body></html>" | open -a /Applications/Safari.app -f

doesn't work. Safari appears to be sniffing the content, and selecting text/plain if it doesn't match <html> promptly. The sniffing isn't completely dim, because

echo '<!-- hello --><html><body>Moo</body></html>' | open -a /Applications/Safari.app -f

is processed as text/html. That's reasonable, but still leaves it unreliable.

What would be ideal is a mime-type option with 'open -f', with or without the -a option. Thus, 'open -m text/html -f' would do the Right Thing, and avoid having to specify the -a option (which is from one point of view a wart) at all.

This is Safari 2.0.2

Norman



[ Reply to This | # ]
Pipe to Safari from stdin
Authored by: lou on Dec 01, '05 04:22:36PM

Ref the posting by tbdavis, I *think* this behavior is because OSX stores the temporary file with a .txt extension. Safari isn't smart enough to look inside the file to determine how to handle it, it depends on the the filename extension to determine how to handle the file.



[ Reply to This | # ]
Pipe to Safari from stdin
Authored by: Afuna on Dec 01, '05 11:33:36PM
open -a /Applications/Safari.app -f <file.html
should just be
open -a /Applications/Safari.app file.html
-- the normal way to use open. I can't get the first one to work over here at all. The -f is used when you're expecting something from the standard input. In this case, there's nothing there, so it's not doing anything.

[ Reply to This | # ]
Pipe to Safari from stdin
Authored by: nxg on Dec 02, '05 07:46:45AM

The first case _is_ reading from stdin: note the angle-bracket before the file.html. That redirects stdin to come from the file. This is similar to

% cat file.html | open -a /Applications/Safari.app -f

but without the extra process. Also it's a standard unix idiom.

As regards the temporary .txt file: this a bit clunky -- I'd have thought a named pipe would be cleaner. But then, it wasn't me implementing it.

I also think this is a bit of a red herring, since it's clear from some of the examples that work that Safari _is_ sniffing the content (otherwise the `Moo' examples wouldn't work), just not very well, or not completely successfully. Allowing a MIME type would be more robust.



[ Reply to This | # ]
Pipe to Safari from stdin
Authored by: Afuna on Dec 02, '05 08:28:15AM

Sorry about that. It was taking a long time to open in Safari, and I wrongly assumed that it was waiting for something, so I used ctrl-c to interrupt the process after a few seconds.

Just tested it now and actually _waited_ until it finished, and I see what you mean now.



[ Reply to This | # ]
Pipe to Safari from stdin
Authored by: xSmurf on Dec 02, '05 01:17:13PM
I've wrote a quick script to address the issue, allows you to preview in any browse and set the extension to what ever you want... It over there:

http://forums.macosxhints.com/showthread.php?p=252816

---
SnitchCTL : http://snitchctl.smurfturf.net/

PM G4 DP 800 / 1.25gb / 120Gb+80Gb / CD/DVD±RW/RAM/DL
- The only APP Smurf

[ Reply to This | # ]

Pipe to Safari from stdin
Authored by: xSmurf on Dec 03, '05 10:27:25AM
If this is a bug, I hope they don't fix it. It is truly an undocumented feature

Not exactly... man open reports:
-f Reads input from standard input and opens the results in the default text editor. End input by sending EOF character (type Control-D). Also useful for piping output to open and having it open in the default text editor.

"ls | open -f" writes the output of the 'ls' command to a file in /tmp and opens the file in the default text editor (as determined by Launch-Services).

---
SnitchCTL : http://snitchctl.smurfturf.net/

PM G4 DP 800 / 1.25gb / 120Gb+80Gb / CD/DVD±RW/RAM/DL
- The only APP Smurf

[ Reply to This | # ]

Pipe to Safari from stdin
Authored by: jacobolus on Feb 15, '06 05:23:22PM
Did you read the hint?
…The -f parameter says that the open command will open the default text editor from stdin.…


[ Reply to This | # ]