LoginSignup
1
0

More than 5 years have passed since last update.

デスクネッツNEOからの「スケジュール予約状況案内」メールから予定を他のカレンダーに登録する AppleScript

Last updated at Posted at 2016-03-22

「スケジュール予約状況案内」メールについて

 グループウェアの「desknet's NEO」では、打合せの予約などで自分以外の人が、自分のスケジュールに予定を登録することができ、その際、メール通知をするように設定しておくと、自分宛てのメールとしてその内容が通知されます。

 そのメール本文は次のような内容になっています。

下記の内容で予定を追加しました。

日付:2016/03/dd 10:00 ~ 2016/03/dd 11:00
登録日:2016/03/xx
登録者:((予定を登録した人の名前))
登録先:((予定が登録された人の羅列))
予定:((予定の件名))
場所:--((未記入だと--になる))
利用設備:((会議室等の名前。未記入は--))
内容:((コメント。未記入はブランク))

他のカレンダー用に必要項目を抽出する

 個人的に使用しているのは、Google カレンダーと、OS Xのカレンダーなので、それに自動で登録するために必要な項目の、通知メールから取り出すスクリプト。
 メールと直接やり取りするのではなく、メール本文を選択&クリップボードにコピーして、このスクリプトに本文を渡すことを前提にしている。

項目取り出しから、登録までのスクリプト

 GoogleカレンダーとMacのカレンダーアプリでは、登録時の日時のフォーマットが異なるため、それぞれのフォーマットに合わせる必要がある。

 このため、スクリプトは二種類になっている。

Googleカレンダー用

 Googleカレンダーには、ブラウザー経由でURLスキームを利用して登録することを前提にしている。

desknetsNEO2GoogleCal.scpt
-- 登録したいGoogleカレンダーのID を指定する
set myCal to "<<登録するカレンダーの個別ID>>@group.calendar.google.com"
set clip to the clipboard as string

on editDate(arg)  -- 日時を整形する(to yyyymmddThhmmss)
    set ans to ""
    repeat with eachChar in arg
        if eachChar as text  "/" and eachChar as text  ":" then
            if eachChar as text = " " then
                set ans to ans & "T"
            else
                set ans to ans & eachChar
            end if
        end if
    end repeat
    return ans & "00"
end editDate

repeat with eachData in paragraphs of clip
    if the number of eachData > 3 then
        if characters 1 thru 3 of eachData as text = "日付:" then
            set Datetime to editDate(characters 4 thru 19 of eachData)
            set Datetime to Datetime & "/"
            set Datetime to Datetime & editDate(characters 23 thru 38 of eachData)
        end if
        if characters 1 thru 3 of eachData as text = "予定:" then
            set Summ to characters 4 thru -1 of eachData as text
        end if
        if characters 1 thru 3 of eachData as text = "場所:" then
            set loc to characters 4 thru -1 of eachData as text
            if loc = "--" then set loc to ""
        end if
    end if
    if the number of eachData > 5 then
        if characters 1 thru 5 of eachData as text = "利用設備:" then
            set loc to characters 6 thru -1 of eachData as text
            if loc = "--" then set loc to ""
        end if
    end if
end repeat

-- GoogleCal への登録
set escSumm to do shell script "perl -MURI::Escape -wle 'print uri_escape(\"" & (Summ as «class utf8») & "\")'"
set escLocation to do shell script "perl -MURI::Escape -wle 'print uri_escape(\"" & (loc as «class utf8») & "\")'"
set CalURL to "http://www.google.com/calendar/event?action=TEMPLATE&src="
set CalURL to CalURL & myCal
set CalURL to CalURL & "&text=" & escSumm & "@" & escLocation
set CalURL to CalURL & "&dates=" & Datetime
-- set CalURL to CalURL & "&location=" & escLocation

open location CalURL

Mac(OS X)カレンダーアプリ用

 Mac用では、カレンダーアプリに直接イベントを書き込むようにしている。
(「iCal」となっている部分はそのままでもスクリプトエディタが自動で環境に合わせて「Calendar」などに変更されます。)

desknetsNEO2iCal
set calName to "2016年の予定" -- 登録するカレンダーの名前
set clip to the clipboard as string

repeat with eachData in paragraphs of clip
    if the number of eachData > 3 then
        if characters 1 thru 3 of eachData as text = "日付:" then
            set sDate to characters 4 thru 19 of eachData
            set sDate to sDate & ":00" as text
            set sDate to date sDate
            set eDate to characters 23 thru 38 of eachData
            set eDate to eDate & ":00" as text
            set eDate to date eDate
        end if
        if characters 1 thru 3 of eachData as text = "予定:" then
            set Summ to characters 4 thru -1 of eachData as text
        end if
        if characters 1 thru 3 of eachData as text = "場所:" then
            set loc to characters 4 thru -1 of eachData as text
            if loc = "--" then set loc to ""
        end if
    end if
    if the number of eachData > 5 then
        if characters 1 thru 5 of eachData as text = "利用設備:" then
            set loc to characters 6 thru -1 of eachData as text
            if loc = "--" then set loc to ""
        end if
    end if
end repeat

-- iCal への登録
tell application "iCal"
    set newEvent to make new event at end of events of calendar calName with properties {summary:Ev, start date:sDate, end date:eDate, location:loc}
    activate
end tell

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0