【问题标题】:How Do I Activate a specific Safari Window using rb-appscript?如何使用 rb-appscript 激活特定的 Safari 窗口?
【发布时间】:2011-10-04 11:13:13
【问题描述】:

我无法让 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] 应该会激活 google 窗口,但这不是正在发生的事情。

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)

【问题讨论】:

  • 你有没有在 Applescript 中试过这个,看看它是否有效?
  • 对,但 rb-appscript 本质上是您的代码与 Applescript 和 OSA 之间的一层。并不是所有的东西都通过 rb-appscript 传递给 Ruby,所以可能会抛出一个错误,即 rb-aapscript 没有传递给你。也就是说,我确实在 Applescript 中尝试过,但它并没有按照@Lri 的回答工作。

标签: ruby macos safari applescript rb-appscript


【解决方案1】:

你不能activatewindows:

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

 

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多