How Do I Activate a specific Safari Window using rb-appscript?

流过昼夜 提交于 2021-02-11 15:25:46

问题


I can't get rb-appscript to activate a specific Safari window. It is always activating the most recently active window.

(in irb, assuming rb-appscript is already installed)

require 'appscript'
include Appscript

safari = app 'Safari'
safari.open_location "http://www.google.com"
safari.open_location "http://www.apple.com"
safari.open_location "http://www.bing.com"
safari.documents.URL.get
=> ["http://www.bing.com/", "http://www.apple.com/", "http://www.google.com.ph/", "http://www.apple.com/startpage/"]
safari.documents[1].URL.get
 => "http://www.bing.com/"
safari.documents[3].URL.get
 => "http://www.google.com.ph/"

Now here comes the hairy part. Activating documents[3] should activate the google window, but this isn't what is happening.

safari.documents[3].activate
 => nil (activates the bing window instead of the google window)
safari.windows[3].activate
 => nil (activates the bing window instead of the google window)

回答1:


You can't activate windows:

app("Safari").windows[its.name.eq("Google")].index.set(1)

 

tell application "Safari" to set index of (windows where name is "Google") to 1


来源:https://stackoverflow.com/questions/6678899/how-do-i-activate-a-specific-safari-window-using-rb-appscript

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