0

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)
Radamanthus
  • 690
  • 2
  • 5
  • 17
  • Have you tried this in straight Applescript to see if it works? – Philip Regan Jul 13 '11 at 12:34
  • 1
    Right, but rb-appscript is essentially a layer between your code and the Applescript and OSA. Not everything gets passed to Ruby by rb-appscript as it should, so there may be an error that is being thrown that rb-aapscript isn't passing to you. That said, I did try this in Applescript and it didn't work per @Lri's answer. – Philip Regan Jul 13 '11 at 13:45

1 Answers1

3

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
Lri
  • 26,768
  • 8
  • 84
  • 82