objective-ccocoascriptingapplescriptadium

Make new chat in Adium using Cocoa 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?


Solution

  • 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];