views:

123

answers:

2

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?

A: 

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];
has
The objc-appscript works fine so far, but it doesn't help me creating a new chat. I just get an empty result and nothing happens.
JR
A: 

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];
Isaac
"I could not find a way to make that chat take the contact" - You can't. Sending `make` (`core`/`crel`) events is partly cripped in SB. You can supply a `with data` parameter or a `with properties` parameter (but not both), and that's it. SB does its own thing for the `new` and `at` parameters, and doesn't allow you to pass any others. Most apps rely on the `with properties` to supply values here, but there's no law that requires this, and Adium is one that doesn't. As I say, to do it with SB you'll have to use raw AE codes. Or use AppleScript/appscript, which speak Apple events properly.
has