How to use ScriptingBridge to tell Safari to open a URL in a new window?

Go To StackoverFlow.com

1

I have an Objective-C app that uses ScriptingBridge to control Safari. It works, but I'm having trouble writing code for a new capability - to tell Safari to open a URL in a new window. Here's the AppleScript that does what I want:

tell application "Safari"
make new document at end of documents
set URL of document 1 to "http://www.apple.com/"
end tell

and here's what I hoped to be the equivalent code using ScriptingBridge:

NSString *appName = @"com.apple.Safari";
safariApp = [SBApplication applicationWithBundleIdentifier:appName];

SafariDocument *doc = [[[safariApp classForScriptingClass:@"document"] alloc] init];
[[safariApp documents] addObject:doc];
doc.path = @"http://www.ford.com";

When I execute the latter code, Safari opens a new window, but the window shows my home page, not www.ford.com.

What's wrong?

2012-04-04 04:26
by Pete Siemsen


0

Here's the solution:

NSDictionary *theProperties = [NSDictionary dictionaryWithObject:@"http://www.ford.com" forKey:@"URL"];
SafariDocument *doc = [[[safariApp classForScriptingClass:@"document"] alloc] initWithProperties:theProperties];
[[safariApp documents] addObject:doc];
[doc release];
2012-04-07 04:54
by Pete Siemsen
Ads