I'm trying to create a new tab in a Safari window from Cocoa using Scripting Bridge. My code looks something like this:
SafariApplication *safari = [SBApplication applicationWithBundleIdentifier:@"com.apple.Safari"];
if ([[safari windows] count] == 0)
{
NSLog(@"No window found. Creating a new one.");
SafariDocument *newDoc = [[[safari classForScriptingClass:@"document"] alloc] init];
[[safari windows] addObject:newDoc];
[newDoc release];
}
else
{
NSLog(@"Seems we already have a safari window");
SafariTab *newTab = [[[safari classForScriptingClass:@"tab"] alloc] init];
[[[safari windows] objectAtIndex:0] addObject:newTab];
[newTab release];
}
The first part if the "if" works, creating a new window. Creating the tab does not. This gets me "-[SafariWindow addObject:]: unrecognized selector sent to instance...", so obviously that's not the way to do it. I can't figure out how windows, documents and tabs relate to each other in Safari. Any help is greatly appreciated.
Thanks,
Thor