以下 AppleScript 代码运行良好:

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

但是我怎样才能使用 Cocoa 的 ScriptingBridge 来做同样的事情呢?

有帮助吗?

解决方案

一般来说,你应该能够按照Apple的方法进行操作 Cocoa 脚本桥编程指南. 。首先,我通过运行为 Adium 创建了一个头文件 sdef /Applications/Adium.app | sdp -fh --basename Adium 在终端中(在当前目录中创建 Adium.h)。生成的头文件提供了有关通过脚本桥进行 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];

其他提示

使用原始的苹果事件代码的短,你不能。应该 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];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top