From: Allison N. <dem...@ma...> - 2008-12-15 12:37:02
|
Hi everyone, I'm having a few problems scripting Safari from Ruby, and I'm wondering if anyone else has had any problems/found solutions. I'm trying to open a URL in Safari. My first attempt looked like this (please excuse any typos, I'm not on the computer that has the source code....) require 'osx/cocoa' include OSX OSX.require_framework 'ScriptingBridge' url = "http://www.blah.com/MyAccount.htm" @safari = SBApplication.applicationWithBundleIdentifier("com.apple.Safari") # so far, so good! # The following is no good, this gives me a document_class of SBProxyByClass document_class = @safari.classForScriptingClass('document') document = document_class.alloc.init document.URL = url @safari.documents << document # the following works, but only if Safari already has a page open - it changes this page to the new URL, which is not what I want to do, I want to open either a new window, or a new tab. It also fails if there is no document already open, as document is set to nil document = @safari.documents.last # document has a class of OSX::SafariDocument document.URL = url #The following does not work, again, the class isn't right... document = OSX::SafariDocument.alloc.init # document.class = SBProxyByClass document.URL = url @safari.documents << document So, I'm a little puzzled. Does anyone know how to do this properly? Alli |