3

Safari and Chrome can execute JavaScript via AppleScript

Safari:

tell application "Safari"
    open location "http://example.com"
    activate
    do JavaScript "alert('example');" in current tab of first window
end tell

Chrome:

tell application "Google Chrome"
    open location "http://example.com"
    activate
    execute front window's active tab javascript "alert('example');"
end tell

Is there a way to do this in Opera?

Note: Same question for Firefox is here: AppleScript - JavaScript execution on Firefox

I thought about asking them together, but I decided to ask two separate questions to be able to accept answers separately.

0

1 Answer 1

0

No, it would seem that Opera does not have an AppleScript dictionary

According to this site:

Opera (www.opera.com/download/) is a speedy, powerful, and expensive ($40) Web browser. If you're looking for AppleScript support, stay far away; Opera has none either.

That fact seems to be supported by the discussion here.


That being said, you might be able to hack around that restriction (but it will be very ugly).

According to here:

To indirectly reach the Console in Opera (checked on v9.6) the shortcut is CTRL + SHIFT + I

I think that is the Windows way, but Mac is probably just command + shift + i.

You get Opera to be the front window, then you use System Events to start typing. For example:

tell application "System Events"
    keystroke "l" using command down
    keystroke "c" using command down
end tell

(In other words, you should just use another browser.)

Sign up to request clarification or add additional context in comments.

1 Comment

This is no longer true, Opera now has an AppleScript dictionary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.