壁紙カレンダーを順に切り換えるAppleScript

三階ラボさんの壁紙カレンダーが素敵で、使わせてもらっている。

カレンダーなので、翌月にしたり、前月に戻したりという欲求がたまにある。デスクトップピクチャを変更するには、右クリックして、デスクトップのバックグラウンドを変更...、好みの月のカレンダー画像を選択することになる。しかし、この手順が結構面倒くさい...。素早く、1動作で済ませたいものだ、と感じて、お決まりのAppleScriptを作ってみた。


tell application "Finder"
set pic_dir to (desktop picture as alias)'s folder as text
set pic_name to (desktop picture as alias)'s name as text --calendar-1003-1280x800-dark.png
set pic_name_elements to my split(pic_name, "-") --{"calendar","1003","1280x800","dark.png"}
set year_month to pic_name_elements's item 2 as number
set year_month to year_month + 1
if (year_month mod 100) > 12 then set year_month to year_month + 100 - 12
if (year_month mod 100) < 1 then set year_month to year_month - 100 + 12
set pic_name_elements's item 2 to year_month
set pic_name to my join(pic_name_elements, "-") try
set desktop picture to file (pic_dir & pic_name) on error
"以下のファイルが見つかりません。" & return & return
display dialog result & pic_name
end try
end tell

on split(sourceText, delimiter) if sourceText = "" then return {} set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {delimiter} set theList to text items of sourceText
set AppleScript's text item delimiters to oldDelimiters
theList
end split

on join(sourceList, delimiter) set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {delimiter} set theText to sourceList as text
set AppleScript's text item delimiters to oldDelimiters
theText
end join


set year_month to year_month + 1

  • 「+ 1」を「- 1」に変更すればOK。


set year_month to year_month - 1


  • やっていることは、ファイル名の年月の部分を見て、翌月なら+1、前月なら-1、している。
    • 年の変わり目の場合は、年も変更して、1月・12月にリセットしている。
  • もし、翌年にしたいなら+100、前年にしたいなら-100、すればよいのだ。
  • あるいは、任意の年月を入力して、それを設定してもよいのだ。


アプリケーション形式で保存して、デスクトップに置いておくことにした。