Search code examples
javascriptapplescriptopera

AppleScript - JavaScript execution on Opera


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.


Solution

  • 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.)