お正月にPCをお休みさせるスクリプト

お正月くらいPCにもお休みさせてあげたいよね!
ということで、AppleScript書いてみました。

-- シャットダウンしたい日付リスト設定
set shutdown_date_list to {"2011-12-29", "2011-12-30", "2011-12-31", "2012-01-01", "2012-01-02"}

-- 日付オブジェクト取得
set the_date to the current date

-- 年、月、日、曜日を取得
set the_year to (year of the_date) as text
set the_month to (month of the_date) as integer as text
set the_day to (day of the_date) as text
set the_weekday to text from character 1 to character 3 of ((weekday of the_date) as text)

-- %02d表記するように
if length of the_month is 1 then
	set the_month to "0" & the_month
end if
if length of the_day is 1 then
	set the_day to "0" & the_day
end if

-- "2011-12-11といった感じの文字列に"
set the date_string to the_year & "-" & the_month & "-" & the_day

-- 起動してから1分くらい待ってみる
delay 60

-- 日付が正月の時は強制PCシャットダウン
repeat with shutdown_date in shutdown_date_list
	if date_string contains shutdown_date then
		tell application "System Events" to shut down
	end if
end repeat