Как активировать конкретное окно Safari с помощью 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] должна активировать окно 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)
1 ответ
Решение
Ты не можешь activate
окна:
app("Safari").windows[its.name.eq("Google")].index.set(1)
tell application "Safari" to set index of (windows where name is "Google") to 1