1

What I have set up is a AppleScript that asks you what website you want to open with a couple options, to make this simple, I only list one option, Google. This is the current code:

if the_button = "Google" then
    site = "http://www.google.com"
    tell application "Google Chrome"
        launch
        tell window 1
            make new tab with properties {URL:site}
            repeat while loading of active tab
                delay 0.1
            end repeat
        end tell
        activate
    end tell

It opens a new tab in Google Chrome, but doesn't put anything in the URL bar or reload/load or anything. I've tried this: Script Safari 5.1 to open a tab But, nothing's working. I'm using Mac OS X Lion 10.7.4 and Google Chrome version 21.0.1180.79. Please help!

Community
  • 1
  • 1
RobotA69
  • 11
  • 1
  • 2

2 Answers2

1

It works for me, but not when Chrome doesn't have open windows or if all windows are minimized. You could add a reopen command to open a new default window or unminimize a window in those cases.

set site to "http://www.google.com"
tell application "Google Chrome"
    reopen
    activate
    tell window 1
        make new tab with properties {URL:site}
    end tell
end tell

Another option might be to use something like do shell script "open " & quoted form of "http://google.com" & " -a Google\ Chrome". It's often closer to the default behavior of browsers.

Lri
  • 26,768
  • 8
  • 84
  • 82
1

Can't you just do this?

tell application "Google Chrome"
    activate
    set theSite to "http://www.google.com/"
    open location theSite
end tell

The “open location” command is part of Standard Additions and is available to all Mac apps. It’s the default way to open a website in any Mac app. You might notice that Safari’s AppleScript dictionary doesn’t even include a way to open a website — it simply uses the standard “open location” command which you can find in the Standard Additions dictionary.

Simon White
  • 686
  • 5
  • 9