The following AppleScript code works fine:
tell application "Adium" to tell first account to make new chat with contacts {first contact} with new chat window
But how can I do the same using Cocoa's ScriptingBridge?
The following AppleScript code works fine:
tell application "Adium" to tell first account to make new chat with contacts {first contact} with new chat window
But how can I do the same using Cocoa's ScriptingBridge?
Short of using raw Apple event codes, you can't. Should work with objc-appscript though. Running your AppleScript command through appscript's ASTranslate tool produces the following:
#import "ADGlue/ADGlue.h"
ADApplication *adium = [ADApplication applicationWithName: @"Adium"];
ADReference *ref = [[adium accounts] at: 1];
ADMakeCommand *cmd = [[[[ref make] newChatWindow: ASTrue] withContacts: [NSArray arrayWithObject: [[[[adium accounts] at: 1] contacts] at: 1]]] new_: [ADConstant chat]];
id result = [cmd send];
Generally, you ought to be able to do it following Apple's Scripting Bridge Programming Guide for Cocoa. To start, I created a header file for Adium by running sdef /Applications/Adium.app | sdp -fh --basename Adium
in Terminal (creates Adium.h in the current directory). The header file produced gives clues about making the AppleScript calls via the Scripting Bridge.
The problem that I ran into is that I cannot see a way, based on the generated header file, to do make new chat with contacts {...} with new chat window
(I can make a new chat and maybe even hook it into a new window, but I could not find a way to make that chat take the contact).
The next best thing might be to use NSAppleScript to execute your valid AppleScript code:
NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:@"tell application \"Adium\" to tell first account to make new chat with contacts {first contact} with new chat window"];
NSDictionary *errorDictionary;
NSAppleEventDescriptor *eventDescriptor = [appleScript executeAndReturnError:&errorDictionary];