Last active
October 19, 2018 01:55
-
-
Save minoki/577a684dc9af43523720 to your computer and use it in GitHub Desktop.
Mail.appで受信した図書館の貸出資料返却日お知らせメールを元に、リマインダーに項目を作るJavaScript for Automation (JXA)スクリプト。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Reminders = Application("Reminders"); | |
function performMailActionWithMessages(messages) | |
{ | |
messages.forEach(function (message) { | |
var content = message.content(); | |
var r = /返却期限日\(Due Date\):(\d+)\/(\d+)\/(\d+)\nタイトル \(Title\):\n(.*)/g; | |
var m; | |
while (m = r.exec(content)) { | |
var year = parseInt(m[1]); | |
var month = parseInt(m[2]); | |
var day = parseInt(m[3]); | |
var dueDate = new Date(year, month-1, day, 17); /* 期限の日の17時を期限日時にする */ | |
var remindMeDate = new Date(dueDate.valueOf() - (3*24 + 17 - 8)*60*60*1000); /* 3日前の午前8時に通知 */ | |
var bookTitle = m[4]; | |
var entry = Reminders.Reminder({ | |
name: bookTitle, | |
/*body: ...,*/ | |
remindMeDate: remindMeDate, | |
dueDate: dueDate | |
}); | |
Reminders.lists["本の返却"].reminders.push(entry); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment