1

I am trying to set the url of Chrome tab using Apple Script. I am using this code. It successfully sets url string, but in order to change url, enter needs to be pressed. This last step makes my code unfunctional, since it doesn't change the current website I am visiting. What workaround do you recommend? Chrome is already open.

tell application "Google Chrome"

    tell application "System Events"
        tell application process "Google Chrome"
            set value of text field 1 of toolbar 1 of window 1 to "http://www.url.com/"

        end tell
    end tell
end tell
4

A way to do it with Chrome's built in scripting:

tell application "Google Chrome" to set URL of active tab of window 1 to "http://example.com"

And to expand your script to press return:

tell application "Google Chrome"
    tell application "System Events"
        tell application process "Google Chrome"
            set (text field 1 of toolbar 1 of window 1)'s focused to true
            set value of text field 1 of toolbar 1 of window 1 to "http://example.com/"
            keystroke return
        end tell
    end tell
end tell
  • Maybe it's my system however your expanded script does not compile. It errors out with Syntax Error Expected “,” but found number. and highlights the 1 after toolbar I'm running Version 49.0.2623.108 (64-bit) of Google Chrome however I suspect it could be because I'm running OS X 10.8.5 and in particular AppleScript 2.2.4 doesn't support that syntax. – user3439894 Apr 6 '16 at 19:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .