当我使用 Apple Scripting Bridge 发送带有附件的消息时,消息的背景设置为黑色,这是一个问题,因为文本也是黑色的。有问题的代码是:
MailApplication *mail = [SBApplication applicationWithBundleIdentifier:@"com.apple.Mail"];
/* create a new outgoing message object */
MailOutgoingMessage *emailMessage =
[[[mail classForScriptingClass:@"outgoing message"] alloc]
initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
emailSubject, @"subject",
[self composeEmailBody], @"content", nil]];
/* add the object to the mail app */
[[mail outgoingMessages] addObject: emailMessage];
/* set the sender, show the message */
emailMessage.sender = [NSString stringWithFormat:@"%@ <%@>",[[[mail accounts] objectAtIndex:playerOptions.mailAccount] fullName],[[[[mail accounts] objectAtIndex:playerOptions.mailAccount] emailAddresses] objectAtIndex:0]];
emailMessage.visible = YES;
/* create a new recipient and add it to the recipients list */
MailToRecipient *theRecipient =
[[[mail classForScriptingClass:@"to recipient"] alloc]
initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
opponentEmail, @"address",
nil]];
[emailMessage.toRecipients addObject: theRecipient];
/* add an attachment, if one was specified */
if ( [playerInfo.gameFile length] > 0 ) {
/* create an attachment object */
MailAttachment *theAttachment = [[[mail classForScriptingClass:@"attachment"] alloc] initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
playerInfo.gameFile, @"fileName", nil]];
/* add it to the list of attachments */
[[emailMessage.content attachments] addObject: theAttachment];
}
/* send the message */
[emailMessage send];
背景颜色的实际变化发生在倒数第二行,即:
[[emailMessage.content attachments] addObject: theAttachment];
上面的代码部分基本上来自 Apple 的 SBSendMail 示例代码。在这个阶段,我实际上只进行了与应用程序中的数据集成所需的更改。如果我在从 Apple 新下载 SBSendMail 示例后构建并运行它,则消息背景也会更改为黑色并执行同一行。附加的文件类型、位置或使用的计算机或操作系统似乎都无关紧要。
这可能是 Apple 脚本桥中的一个错误,但有没有人遇到过这个问题并找到了解决方案?或者,是否有人知道 MailOutgoingMessage 实例的背景颜色是否可以通过脚本桥接更改?