処理対象の月(年/月)の入力を求めるサブルーチンです。単月だけでなく、範囲を「…」で指定することも可能で、「2008/3…4」とか「2008/12…2009/3」といった指定が可能です。

返り値は、範囲の開始と終了がdateオブジェクトで返ってきます。
「2008/12」と指定した場合、{date “2008年 12月 1日 月曜日 0:00:00 AM”, date “2009年 1月 1日 木曜日 0:00:00 AM”}。
「2008/3…7」と指定した場合、{date “2008年 3月 1日 土曜日 0:00:00 AM”, date “2008年 8月 1日 金曜日 0:00:00 AM”}。
「2008/12…2009/3」と指定した場合、{date “2008年 12月 1日 月曜日 0:00:00 AM”, date “2009年 4月 1日 水曜日 0:00:00 AM”}。
もともとは、iCalに重複登録されたイベントの削除を行うためのサブルーチンだったので(mobile meとかiPhoneとかEntourageなどとあちこちシンクロしていたらそうなったらしい)、その削除対象を指定するために作ったものです。返り値の終了日時がびみょーに1秒ほどオーバーしているところが気になる(すでに翌日になっている)場合には、終了日時から1秒引いておくなどして使ってみてください。
| スクリプト名:月あるいは期間入力サブルーチン |
–指定期間のイベントを取得 set todayDat to current date set targYear to (year of todayDat) as string set targMonth to (month of todayDat as number) as string set aTarg to text returned of (display dialog "重複イベントの削除対象月は?(YYYY/MM)" default answer (targYear & "/" & targMonth)) set {sDate, eDate} to getRangeFromDateText(aTarg) of me
on getRangeFromDateText(aText) if aText does not contain "…" then –普通にYYYY/MM指定のみ行った場合 set sDate to (aText & "/1") set eDate to (date sDate) + (getMlen(year of (date sDate), month of (date sDate)) of me) * days set sDate to date sDate else –期間を「YYYY/MM…YYYY/MM」 で指定した場合 set curDelim to AppleScript’s text item delimiters set AppleScript’s text item delimiters to "…" set tList to text items of aText set AppleScript’s text item delimiters to curDelim set item1T to contents of item 1 of tList set item2T to contents of item 2 of tList set sDate to date retYYYYMDD(item1T) of me set eDate1 to date retYYYYMDD(item2T) of me set eDate to eDate1 + (getMlen(year of sDate, month of eDate1) of me) * days end if return {sDate, eDate} end getRangeFromDateText
on retYYYYMDD(aText) if aText contains "/" then set bText to aText & "/1" else set thisYear to (year of (current date)) as string set bText to thisYear & "/" & aText & "/1" end if return bText end retYYYYMDD
–指定月の長さを得る(日数) on getMlen(aYear, aMonth) set aYear to aYear as number set aMonth to aMonth as number set aDat to (aYear as text) & "/" & (aMonth as text) & "/1" if aMonth is not equal to 12 then set eDat to ((aYear as text) & "/" & (aMonth + 1) as text) & "/1" else set eDat to ((aYear + 1) as text) & "/" & (1 as text) & "/1" end if set eDat to date eDat set eDat to eDat - 1 set mLen to day of eDat return mLen end getMlen |
|
▼新規書類に ▼カーソル位置に ▼ドキュメント末尾に
|