New tab in Safari window from Cocoa and Scripting Bridge
Posted
by Thor Frølich
on Stack Overflow
See other posts from Stack Overflow
or by Thor Frølich
Published on 2010-05-26T10:44:32Z
Indexed on
2010/05/26
13:21 UTC
Read the original article
Hit count: 409
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
© Stack Overflow or respective owner