Paste into Safari's Console

Discussion in 'Mac Programming' started by MikePancho, Dec 8, 2013.

  1. MikePancho macrumors newbie

    Joined:
    Dec 20, 2012
    #1
    if there any way you can copy the text from "text file #1" into safari's web console using a .sh file?
    thanks
    -- Mike
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    Safari's Console is an output-only error-message console. It's not a command interpreter.

    Terminal.app is where you can input commands in a window and see their output.


    Please explain exactly what you're trying to accomplish, that you think Safari's console is the solution.

    You've posted an XY Problem, where you want to do X, and you think Y is the best way of doing so. Instead of asking about X, you ask about Y.
    http://www.perlmonks.org/?node_id=542341
     
  3. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #3
    Actually it is, apart from commands, you can execute Javascript and interact with the DOM and see the effects as you type.
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    I've never seen this. Please describe exactly which window or pane this is, and the menu-items or other commands that cause it to appear.

    And which version of Safari does this appear in.

    I have both the Develop and Debug menus enabled in my Safari versions, and nothing I've yet seen brings up such a "console".
     
  5. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #5
    Open the WebInspector, press 'console' in the upper right corner, alternatively the lower left corner with the '>' symbol for a split view.

    For a demo on this page try this:

    Code:
    $('body').css('background-color', 'red')
    
    Edit: Also from Apple's documentation, "The console offers a way to inspect and debug your webpages. Think of it as the Terminal of your web content. The console has access to the DOM and JavaScript of the open page. Use the console as a tool to modify your web content via interactive commands and as a teaching aid to expand your knowledge of JavaScript."
     
  6. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #6
    Thanks for that, I hadn't noticed it before.

    For future readers of this thread, Apple's Safari Console guide is here (for now):
    https://developer.apple.com/library...l/Safari_Developer_Guide/Console/Console.html


    So getting back to the OP's question...

    I think he's asking if he can write a shell script that tells Safari to open its Web Inspector window, then copy and paste some series of commands from a text-file into that window's console pane. The pasted commands would presumably be valid Safari-console commands, rather than, say, shell commands, or /bin or /usr/bin commands.

    The first step of an answer to that might be getting the contents of the text-file into the system clipboard. One way to do that is the 'pbcopy' command:
    https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/pbcopy.1.html
    Simple example:
    Code:
    pbcopy <"path/to/your/text file #1"
    
    The logical next steps would be to tell Safari to:
    1. Open its Web Inspector window.
    2. Activate the console pane.
    3. Paste the clipboard.
    4. Press return.
     

Share This Page