Paste into Safari's Console

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

  1. MikePancho macrumors newbie

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

    Aug 9, 2009
    Safari's Console is an output-only error-message console. It's not a command interpreter. 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.
  3. subsonix macrumors 68040

    Feb 2, 2008
    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

    Aug 9, 2009
    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

    Feb 2, 2008
    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:

    $('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

    Aug 9, 2009
    Thanks for that, I hadn't noticed it before.

    For future readers of this thread, Apple's Safari Console guide is here (for now):

    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:
    Simple example:
    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