使用 Cocoa ScriptingBridge 在 Adium 中创建新聊天

发布于 2024-08-24 15:16:41 字数 222 浏览 9 评论 0原文

下面的 AppleScript 代码工作正常:

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

但是我怎样才能使用 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红颜悴 2024-08-31 15:16:41

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

我遇到的问题是,我无法根据生成的头文件找到一种方法来使用新的聊天窗口与联系人{...}进行新的聊天(我可以创建一个新的聊天窗口)(我可以创建一个新的聊天窗口)聊天,甚至可能将其挂接到新窗口中,但我找不到一种方法让该聊天接受联系人)。

下一个最好的办法可能是使用 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];

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];
燕归巢 2024-08-31 15:16:41

如果不使用原始的 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];

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文