2012-04-04 61 views
1

我有一个使用ScriptingBridge来控制Safari的Objective-C应用程序。它可以工作,但是我无法为新功能编写代码 - 告诉Safari在新窗口中打开一个URL。这里是AppleScript的是做什么,我想:如何使用ScriptingBridge通知Safari在新窗口中打开URL?

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

和这里就是我希望使用是等效代码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"; 

当我执行后的代码,Safari浏览器打开一个新窗口,但窗口显示我的主页,而不是www.ford.com。

怎么了?

回答

0

这里的解决方案:

NSDictionary *theProperties = [NSDictionary dictionaryWithObject:@"http://www.ford.com" forKey:@"URL"]; 
SafariDocument *doc = [[[safariApp classForScriptingClass:@"document"] alloc] initWithProperties:theProperties]; 
[[safariApp documents] addObject:doc]; 
[doc release];