script spdUp property selList : missing value property dList : {} property eList : {} property fList : {} end script
–set t1 to current date
–データの初期化 set dList of spdUp to {} set eList of spdUp to {} set selList of spdUp to {}
–iPhotoからデータを取得する tell application “iPhoto” set selList of spdUp to selection if (selList of spdUp) = {} then display dialog “何も選択されていません。” buttons {“OK”} default button 1 return end if repeat with i in (selList of spdUp) set the end of (dList of spdUp) to date of i end repeat end tell
–ソート set (dList of spdUp) to shellSort5(dList of spdUp) of me
–選択中の写真の最初の日付、最近の日付を求める set minDate to contents of first item of (dList of spdUp) set maxDate to contents of last item of (dList of spdUp)
–開始日、終了日の間の{年,月}のリストを取得する set mmList to retYearMonthWithinPeriod(minDate, maxDate) of me
set aLen to length of (dList of spdUp) set hitList to {}
set aCount to 0
set aPointer to 1 set hitF to false
repeat with i in mmList set {aYear, aMonth} to i set sDate to (aYear as string) & “/” & (aMonth as string) & “/1″ set eDate to (aYear as string) & “/” & (aMonth as string) & “/” & getMlen(aYear, aMonth) of me as string set sDateObj to date sDate set eDateObj to date eDate repeat set j to contents of item aPointer of (dList of spdUp) if (sDateObj ≤ j) and (j ≤ eDateObj) then if hitF = false then set hitF to true set aCount to 1 set aPointer to aPointer + 1 else set aCount to aCount + 1 set aPointer to aPointer + 1 end if else if hitF = true then set the end of hitList to {aYear, aMonth, aCount} set aCount to 0 set hitF to false exit repeat else set the end of hitList to {aYear, aMonth, 0} exit repeat end if end if if aPointer > aLen then exit repeat end if end repeat if aPointer > aLen then exit repeat end if end repeat
if hitF = true then set the end of hitList to {aYear, aMonth, aCount} end if
–set t2 to current date –set t3 to t2 -t1 –> 93 sec
hitList –> {{2009, 4, 2}, {2009, 5, 0}, {2009, 6, 0}, {2009, 7, 25}, {2009, 8, 0}, {2009, 9, 0}, {2009, 10, 1}, {2009, 11, 2}, {2009, 12, 7}, {2010, 1, 38}, {2010, 2, 41}, {2010, 3, 4}, {2010, 4, 36}, {2010, 5, 5}, {2010, 6, 3}, {2010, 7, 36}, {2010, 8, 26}, {2010, 9, 49}, {2010, 10, 8}, {2010, 11, 61}, {2010, 12, 23}, {2011, 1, 32}, {2011, 2, 40}, {2011, 3, 0}, {2011, 4, 26}, {2011, 5, 44}, {2011, 6, 10}, {2011, 7, 32}, {2011, 8, 41}, {2011, 9, 0}, {2011, 10, 0}, {2011, 11, 39}, {2011, 12, 51}, {2012, 1, 25}, {2012, 2, 0}, {2012, 3, 51}, {2012, 4, 23}}
on retYearMonthWithinPeriod(sDate, eDate) set sYear to year of sDate set sMonth to month of sDate as number set eYear to year of eDate set eMonth to month of eDate as number set mList to {} if sYear is equal to eYear then repeat with i from sMonth to eMonth set the end of mList to {sYear, i} end repeat else if sYear + 1 = eYear then repeat with i from sMonth to 12 set the end of mList to {sYear, i} end repeat repeat with i from 1 to sMonth set the end of mList to {eYear, i} end repeat else repeat with i from sMonth to 12 set the end of mList to {sYear, i} end repeat repeat with i from (sYear + 1) to (eYear - 1) repeat with ii from 1 to 12 set the end of mList to {i, ii} end repeat end repeat repeat with i from 1 to sMonth set the end of mList to {eYear, i} end repeat end if return mList end retYearMonthWithinPeriod
–最大値を取得する on maximumFromList(nList) script o property nl : nList end script set max to item 1 of o’s nl repeat with i from 2 to (count nList) set n to item i of o’s nl if n > max then set max to n end repeat return max end maximumFromList
–最小値を取得する on minimumFromList(nList) script o property nl : nList end script set min to item 1 of o’s nl repeat with i from 2 to (count nList) set n to item i of o’s nl if n < min then set min to n end repeat return min end minimumFromList
–指定月の長さを得る(日数) on getMlen(aYear, aMonth) 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 sDat to date aDat set eDat to date eDat set eDat to eDat - 1 set mLen to day of eDat return mLen end getMlen
–プレーンなAppleScriptベースでは最速ソート on shellSort5(aSortList) – スクリプトオブジェクトを使用 script oBj property list : aSortList end script set len to count oBj’s list’s items set gap to 1 repeat while (gap ≤ len) set gap to ((gap * 3) + 1) end repeat repeat while (gap > 0) set gap to (gap div 3) if (gap < len) then repeat with i from gap to (len - 1) set temp to oBj’s list’s item (i + 1) set j to i repeat while ((j ≥ gap) and (oBj’s list’s item (j - gap + 1) > temp)) set oBj’s list’s item (j + 1) to oBj’s list’s item (j - gap + 1) set j to j - gap end repeat set oBj’s list’s item (j + 1) to temp end repeat end if end repeat return oBj’s list end shellSort5
|