Why won't this HTML script work?

Discussion in 'Apple' started by dave, Mar 7, 2006.

  1. dave

    dave Guest

    open -a /Applications/Safari.app -f << EOF
    The result:

    Safari can't find the file.
    No file exists at the address
    /private/var/tmp/folders.0/TemporaryItems/36D7ADCE-EA2F-4A52-8007-26CC7CCDA1D0-7650-0000343C910DDACF.txt.

    What can be done to correct this? Thanks for your help.
     
    dave, Mar 7, 2006
    #1
    1. Advertisements

  2. The problem is that the open command spawns a background process to run
    the application, and then returns to the shell prompt. The temporary
    file used for the here-document is deleted by the shell when the command
    exits, so it's no longer available for Safari to access.

    You need to create the file yourself, so that it won't be deleted.

    cat <<EOF >/tmp/tempfile.html
    ....
    EOF
    open -a /Applications/Safari.app -f /tmp/tempfile.html
     
    Barry Margolin, Mar 7, 2006
    #2
    1. Advertisements

  3. dave

    Tim McNamara Guest

    What is it that you are trying to do with your "script?" Your "script"
    doesn't work because it's not recognizably intended to *do* anything.

    And where are you running this "script?"
     
    Tim McNamara, Mar 7, 2006
    #3
  4. dave

    Warren Oates Guest

    Well, this worked for me, but Safari doesn't render the HTML, it just
    lists the "code."

    The -f switch sends your commands to a temp file, which safari reads in
    as a .txt file, not as an .html file, so I don't know a way to deal with
    that.

    What are you trying to do exactly?
     
    Warren Oates, Mar 7, 2006
    #4
  5. dave

    Warren Oates Guest

    No, I tried that. Only a cursory attempt; this doesn't seem like it's
    going anywhere. If you could pipe the output of open -f through a script
    that changed the extension, maybe good things, but I don't know if
    that's even possible.
     
    Warren Oates, Mar 8, 2006
    #5
  6. dave

    Warren Oates Guest

    True, but it would render in "quirks mode" if the browser saw it as
    html, and not txt.

    I wish the OP would tell us what he wants to achieve; it seems like he's
    trying to invent something (dynamic web pages?) that already exists.
     
    Warren Oates, Mar 8, 2006
    #6
  7. dave

    Simon Slavin Guest

    Correct diagnosis. The file needs to be written as something with a MIME
    type that Safari will interpret rather than simply listing as text.
    He's trying to work an exploit under Mac OS X and Safari: have a web page
    write an arbitrary shell script and execute it. Fortunately, that
    particular exploit won't work without significant tweaking of the MIME
    management system.

    Simon.
     
    Simon Slavin, Mar 9, 2006
    #7
  8. dave

    Warren Oates Guest

    Interesting. I'm not sure how the web page could write the script,
    though. Is there some documentation of this?
     
    Warren Oates, Mar 9, 2006
    #8
  9. dave

    David Magda Guest

    To the OP,

    It may help if you write proper HTML (TITLE inside BODY?).

    But anyways, try the following:

    open -a /Applications/Safari.app -f << EOF
    <html>
    <head>
    <title>Test</title>
    <body>
    test
    </body>
    EOF

    You don't need the Content-type "header".
     
    David Magda, Mar 10, 2006
    #9
  10. dave

    Warren Oates Guest

    That still won't render the HTML. This isn't about correct HTML, which
    Safari only vaguely cares about anyway. The -f switch creates a temp
    file with a .txt extension, and you'd have to mess with Safari's
    "internals" to get it to parse such a file as HTML.
     
    Warren Oates, Mar 10, 2006
    #10
  11. dave

    David Magda Guest

    *shrug* I'm using Safari Version 2.0.2 (416.13) and it works for me.
     
    David Magda, Mar 11, 2006
    #11
  12. dave

    Eric Lindsay Guest

    Using proper HTML won't help.
    You also don't need the <html> <head> or <body> tags, or their closing
    tags, as they are all optional in HTML (the elements they invoke are
    identified automatically). You should however use a block element tag
    <p> on the word test. But it doesn't matter how you organise the HTML,
    Safari still won't treat it as HTML (unless it comes with an HTTP
    header, or you open it from the Safari file open menu).
     
    Eric Lindsay, Mar 11, 2006
    #12
  13. dave

    Warren Oates Guest

    I'm not sure why. I've got 2.0.3 (417.8) and it simply displays the
    text. Same thing with Firefox and Camino. Is this some security thing
    that the OP may have been trying to mess with?
     
    Warren Oates, Mar 11, 2006
    #13
  14. dave

    David Magda Guest

    Seems like it: I'm now at 2.0.3 as well and it no longer works. Looks
    like the upgrade to 10.4.5 did it.
     
    David Magda, Mar 14, 2006
    #14
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.