AppleScript - JavaScript execution on Opera

放肆的年华 提交于 2019-12-23 16:26:39

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/14383302/applescript-javascript-execution-on-opera

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!