ページ

2008年3月15日土曜日

ADCサンプルより - SBSendEmail

このエントリーをブックマークに追加 このエントリーを含むはてなブックマーク

ADCサンプルより。

SBSendEmail
(2008-02-28)

Descriptionより引用
This sample illustrates how to use the Scripting Bridge Framework to tell the Mail application to send an email message with optional attachments. The included readme file provides detailed discussion of the steps involved in creating this sample.

Scripting Bridge Frameworkを使い Mail.appからメールを送るサンプル。
実行するとメール送信に必要な情報を入力するウィンドウが表示される。



"send"ボタンを押すと Mail.app が起動され入力した内容でメールが送られる。

ソースコードは Controller.m だけで構成されていてシンプル。
ポイントは SBApplication を使った Mailアプリケーションの操作。

MailApplication や MailOutgoingMessage などのオブジェクトを取得して、これに対して操作を行う。
Controller.m(抜粋)

- (IBAction)sendEmailMessage:(id)sender {

/* create a Scripting Bridge object for talking to the Mail application */
MailApplication *mail = [SBApplication
applicationWithBundleIdentifier:@"com.apple.Mail"];

/* create a new outgoing message object */
MailOutgoingMessage *emailMessage =
[[[mail classForScriptingClass:@"outgoing message"] alloc]
initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
[self.subjectField stringValue], @"subject",
[[self.messageContent textStorage] string], @"content",
nil]];

/* add the object to the mail app */
[[mail outgoingMessages] addObject: emailMessage];

/* set the sender, show the message */
emailMessage.sender = [self.fromField stringValue];
emailMessage.visible = YES;
   :
   :



MailApplicationは Mail.h で定義されていて SBApplication のサブクラスとなっている。
Mail.h
@interface MailApplication : SBApplication


他にもスクリプティング向けにたくさんのクラス定義が提供されているのがわかる。

@class MailItem, MailApplication, MailColor, MailDocument, MailWindow, MailText, MailAttachment, MailParagraph, MailWord, MailCharacter, MailAttributeRun, MailOutgoingMessage, MailLdapServer, MailApplication, MailMessageViewer, MailSignature, MailMessage, MailAccount, MailImapAccount, MailMacAccount, MailPopAccount, MailSmtpServer, MailMailbox, MailRule, MailRuleCondition, MailRecipient, MailBccRecipient, MailCcRecipient, MailToRecipient, MailContainer, MailHeader, MailMailAttachment;


- - - -
Scripting Bridge を使うと簡単に外部アプリを操作できることがわかった。ADCでは他にファインダの操作などのサンプルも紹介されている。ところでヘッダファイル Mail.h はビルドディレクトリ内に存在するがこれはいったいどこからやってきたのか?