AppleScript referencing tabs suddently breaking on Chrome

applescriptgoogle-chrome

I've been successfully using a script for a long time, which uses Chrome to calculate execute some javascript and return the result.

tell application "Google Chrome"
    tell window 1
        tell tab 1
            [do something here]
        end tell
    end tell
end tell

Today, after many months, I tried editing the script but the AppleScript Editor is refusing to save it (even without any changes, e.g. after typing a space and then deleting it…), showing an error message:

Syntax Error
Expected end of line but found number.

while highlighting the 1 of tab 1 as being the offender…

What is wrong with the latest version of the applescript editor or of Chrome? Any ideas how to work around this problem?

Best Answer

I can actually get your example to work with no problems, just doing something simple:

tell application "Google Chrome"
  tell window 1
    tell tab 1
        get URL
    end tell
  end tell
end tell

That makes me think the problem might be in the "do something here" section of your script—I've never found Applescript's error messages to be very reliable.

That said, you could also try shortening your code:

tell application "Google Chrome"
  tell active tab of first window
    [do something here]
  end tell
end tell

Using my earlier, super simple example, this works for me:

tell application "Google Chrome"
  get URL of active tab of first window
end tell

I should also note that I'm using Script Editor 2.7 (176) on Yosemite 10.10.1