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

Go To


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 ""
end tell

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

NSString *appName = @"";
safariApp = [SBApplication applicationWithBundleIdentifier:appName];

SafariDocument *doc = [[[safariApp classForScriptingClass:@"document"] alloc] init];
[[safariApp documents] addObject:doc];
doc.path = @"";

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

What's wrong?

2012-04-04 04:26
by Pete Siemsen


Here's the solution:

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