0

以下 AppleScript 代码可以正常工作:

tell application "Adium" to tell first account to make new chat with contacts {first contact} with new chat window

但是如何使用 Cocoa 的 ScriptingBridge 做同样的事情呢?

4

2 回答 2

0

如果不使用原始 Apple 事件代码,则不能。不过应该与objc-appscript一起使用。通过 appscript 的 ASTranslate 工具运行 AppleScript 命令会产生以下结果:

#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];
于 2010-03-13T21:46:04.017 回答
0

通常,您应该能够按照 Apple 的Cocoa 脚本桥编程指南进行操作。首先,我通过sdef /Applications/Adium.app | sdp -fh --basename Adium在终端中运行为 Adium 创建了一个头文件(在当前目录中创建 Adium.h)。生成的头文件提供了有关通过 Scripting Bridge 进行 AppleScript 调用的线索。

我遇到的问题是,我看不到基于生成的头文件的方法make new chat with contacts {...} with new chat window(我可以进行新的聊天,甚至可以将其挂接到新窗口中,但我找不到一种方法来做到这一点聊天拿联系方式)。

下一个最好的方法可能是使用NSAppleScript来执行您的有效 AppleScript 代码:

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];
于 2010-03-14T06:19:04.903 回答