我的问题的动机是以下文档,它描述了如何使用 ScriptingBridge 集成 mail.app:
http://developer.apple.com/mac/library/samplecode/SBSendEmail/Introduction/Intro.html
我也尝试对 Entourage 应用类似的技术,但无法得到到目前为止的任何结果。我知道使用 AppleScript 可以帮助我解决问题,并且 mactech.com 有大量相关文档。
但我发现这种 ScriptingBridge 技术很优雅,并且想弄清楚为什么它对我的 Entourage 不起作用。
最大的问题似乎是我无法根据 Mail 中的名称创建脚本类,因为 Entourage 的接口与 Mail 的接口不同,正如其标头所示。
有人可以告诉我我缺少什么或提供任何关于为什么这行不通的提示吗?
我还添加了示例代码
`
MicrosoftEntourageApplication * mail = [SBApplication
applicationWithBundleIdentifier:@"com.Microsoft.Entourage"];
MicrosoftEntourageOutgoingEmailMessage * emailMessage =
[[[mail classForScriptingClass:@"outgoing message"] alloc]
initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
@"my sample subject", @"subject",
@"my sample body", @"content",
nil]];
//then i create a set of recipients and try to use "to recipient" as the string scripting class id, but MicrosoftEntourageRecipient is returned as nil
MicrosoftEntourageRecipient * theRecipient =
[[[mail classForScriptingClass:@"to recipient"] alloc]
initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
@"[email protected]", @"address",
nil]];
`
我试图让简单的事情发挥作用,我什至没有专注于我现在应该做的任务。
我是一个 Cocoa 初学者(并且愿意学习),请原谅我的语法幼稚,并在回答我的问题之外在示例代码中指出它们。
最好的问候,
萨勃拉曼尼亚
The motivation for my question is the following doc, which describes how mail.app could be integrated using ScriptingBridge:
http://developer.apple.com/mac/library/samplecode/SBSendEmail/Introduction/Intro.html
I tried to apply a similar technique with Entourage as well but could not get any results so far. I understand that using AppleScript would help me solve my problem and mactech.com has extensive documentation for doing so.
But i find this ScriptingBridge technique elegant and want to figure why it is not working for me with Entourage.
The biggest problem seems to be my inability to create Scripting classes based on their names as it happens in Mail because Entourage has a different interface than Mail as their headers indicate.
Could someone please tell me what I am missing or provide any sort of hint on why this wont work?
I am also adding sample code
`
MicrosoftEntourageApplication * mail = [SBApplication
applicationWithBundleIdentifier:@"com.Microsoft.Entourage"];
MicrosoftEntourageOutgoingEmailMessage * emailMessage =
[[[mail classForScriptingClass:@"outgoing message"] alloc]
initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
@"my sample subject", @"subject",
@"my sample body", @"content",
nil]];
//then i create a set of recipients and try to use "to recipient" as the string scripting class id, but MicrosoftEntourageRecipient is returned as nil
MicrosoftEntourageRecipient * theRecipient =
[[[mail classForScriptingClass:@"to recipient"] alloc]
initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
@"[email protected]", @"address",
nil]];
`
I am trying to make the simple thing work, I am not even concentrating on the task I am supposed to do now.
I am a Cocoa beginner( and willing to learn ), please excuse an syntactic naivetes and do point them out in the sample code, in addition to answering my question.
Best Regards,
Subramanian
发布评论
评论(1)
一些事情:
如果您遇到困难,请首先弄清楚如何在 AppleScript 中做到这一点。这就是大多数应用程序脚本编写者所使用的(即最能帮助您的人)以及几乎所有文档的编写目的。 (就像您确实需要学习一些 ObjC 才能从 Python、Ruby 等中使用 Cocoa 一样)。
脚本桥笨重、混乱且容易出现问题应用程序兼容性问题,因此将工作的 AppleScript 代码转换为它可能会很棘手(如果不是不可能的话),具体取决于您的目标应用程序、您正在使用的命令等等。根据记忆,我认为 Entourage 是它出错的应用程序之一,在这种情况下,除非您求助于使用原始 Apple 事件代码,否则您就不走运了。其他选项有 objc-appscript (m'baby),它不太容易出现此类问题,还有 AppleScriptObjC ( 10.6+),它允许您直接从 AppleScript 调用 ObjC 类,反之亦然。
您是否看过CSMail?
Entourage 将在 Office 2010 中消失,取而代之的是 Outlook,因此您可能不想投入大量时间来弄清楚如何为其编写 SB 代码。
A few things:
If you're stuck, first figure out how to do it in AppleScript. That's what most application scripters use (i.e. the folks best able to help you) and what almost all documentation is written for. Realistically, if you want to do much application scripting, you really need to learn some AppleScript (just as you really need to pick up a bit of ObjC to use Cocoa from Python, Ruby, etc).
Scripting Bridge is clunky, obfuscated and prone to application compatibility problems, so translating working AppleScript code to it can be tricky, if not impossible, depending on the application you're targeting, the commands you're using, and so on. From memory, I think Entourage is one of the apps it trips up on, in which case you're out of luck unless you resort to using raw Apple event codes. Other options are objc-appscript (m'baby), which is much less prone to such problems, and AppleScriptObjC (10.6+), which lets you call ObjC classes directly from AppleScript and vice-versa.
Have you looked at CSMail?
Entourage is going away in Office 2010 in favour of Outlook, so you may not want to invest a huge of time figuring out how to write SB code for it anyway.