AppleScriptでメールを読み込みたい

オンラインの中国語会話の予約をウェブですると以下のようなメールが来ます。

このメールの中でレッスン日時「2017/02/14」というところをイベントの開始日

講師名「ジョキ講師」というところをイベント名としてカレンダーに追加したいと思っています。

イベント開始時刻は5行目の10文字目

講師名は6行目の7文字目に書いてあります。

イベント名をename、開始時刻をestartという変数に入れたいと思っています。

どうやってデータを入れたらよいかを教えて下さい。

kosuke-ms 様


レッスンの予約が完了しました。


【レッスン日時】:2017/02/14 21:00-21:25

【講師名】:ジョキ 講師


============ ご利用までの注意事項 ==============

MacBook Pro (Retina, 15-inch, Late 2013), iOS 9.0.2

投稿日 2017/02/13 03:09

返信
返信: 8

2017/02/14 02:41 Oscar86 への返信

度々、失礼致します。

Oscar86 による書き込み:

「受信したメール」の指定がされていないようなのでまだうまくいきません。


1)この部分のスクリプトはどの様になっているのでしょうか?


2)受信したメール(メッセージ)のオブジェクトがあれば、そこからcontentのプロパティを取得します。 例えば、以下のスクリプトは、Macにインストールされていたメールルールのサンプルに少し手を加えたものですが(動作は未確認です)、set theContent to content of eachMessageの部分でメールの本文を取り出しています。


using terms from application "Mail"

on perform mail action with messagestheMessagesfor ruletheRule

tell application "Mail"

set theText to "This AppleScript is intended to be used as an AppleScript rule action, but is also an example of how to write scripts that act on a selection of messages or mailboxes." & return & return & "To view this script, hold down the option key and select it again from the Scripts menu."

repeat with eachMessage in theMessages

set theSubject to subject of eachMessage

set theContent to content of eachMessage

try


-- If this is not being executed as a rule action,


-- getting the name of theRule variable will fail.

set theRuleName to name of theRule

set theText to "The rule named '" & theRuleName & "' matched this message:"

set theText to theText & return & return & "Subject: " & theSubject


display dialogtheText

set theText to ""

end try

end repeat

if theText is not equal to "" then


display dialogtheTextbuttons {"OK"} default button 1

end if

end tell

end perform mail action with messages

end using terms from

2017/02/13 04:57 Oscar86 への返信

以下のAppleScritpが参考になりませんか?


set str to "kosuke-ms


レッスンの予約が完了しました。


【レッスン日時】:2017/02/14 21:00-21:25

【講師名】:ジョキ講師"


set p5 to paragraph 5 of str--> "【レッスン日時】:2017/02/14 21:00-21:25"

set p6 to paragraph 6 of str-->"【講師名】:ジョキ 講師"


set ename to text 7 thru -1 of p6 --> "ジョキ講師"   -1はテキストの最後の文字を示します。

set estart to text 21 thru 25 of p5 --> " 21:00"


こちらのガイドも確認しておくと良いと思います。 → text

2017/02/13 03:16 Oscar86 への返信

失礼致します。 お使いのMacのOSが10.7 (Lion)となっていますが、あっていますでしょうか? その場合、OSをアップグレードしない特別な理由があるのでしょうか? 最近のOSでは、AppleScriptを使わなくても、メールの本文内の日付を検出してカレンダーに追加する機能がありますよ。 → メールで見つかったイベントや連絡先などの項目を使用する

2017/02/13 05:00 T22T への返信

ありがとうございます。

メールを受信すると同時にスクリプトが起動するようになっているのですが、「受信したメール」の指定がされていないようなのでまだうまくいきません。もしよろしければどうやって受信したメールのテキストを読み込むのかを教えていただけませんでしょうか?

このスレッドはシステム、またはAppleコミュニティチームによってロックされました。 問題解決の参考になる情報であれば、どの投稿にでも投票いただけます。またコミュニティで他の回答を検索することもできます。

AppleScriptでメールを読み込みたい

Apple サポートコミュニティへようこそ
Apple ユーザ同士でお使いの製品について助け合うフォーラムです。Apple Account を使ってご参加ください。