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

发布于 2024-11-19 23:38:33 字数 842 浏览 3 评论 0原文

我无法让 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)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最美的太阳 2024-11-26 23:38:33

您无法激活窗口

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

tell application "Safari" to set index of (windows where name is "Google") to 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文