如何使用rb-appscript激活特定的Safari窗口?

时间:2011-07-13 12:30:38

标签: ruby macos safari applescript rb-appscript

我无法获取rb-appscript来激活特定的Safari窗口。它始终激活最近激活的窗口。

(在irb中,假设已经安装了rb-appscript)

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/"

现在这里有毛茸茸的部分。激活文档[3]应激活谷歌窗口,但这不是正在发生的事情。

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 个答案:

答案 0 :(得分:3)

你不能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