今日の日付をクリップボードにコピーするAppleScript その2
先日書いた「今日の日付をクリップボードにコピーするAppleScript」をもう少し実用的に、且つ、AppleScript の書き方を思い出そうと、いろいろ修正してみました。
今度のものは一度いろんな様式の日付の候補リストを表示し、その中から選択したものをクリップボードにコピーするようになってます。
以下、ソース。
set theDate to current date
set theYear to year of theDate as text
set theGengouYear to "平成" & (((year of theDate) - 1988) as text)
set theYY to characters 3 thru 4 of theYear as text
set theMonth to month of theDate as integer as text
set theMM to zeroPrefix(theMonth)
set theDay to day of theDate as text
set theDD to zeroPrefix(theDay)
set theYoubi to item (weekday of theDate as integer) of {"日", "月", "火", "水", "木", "金", "土"}
set theWDY to item (weekday of theDate as integer) of {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}
set theTime to time string of theDate as text
set theHHMM to zeroPrefix((hours of theDate) as text) & ":" & zeroPrefix((minutes of theDate) as text)
set theText1 to theYear & "年" & theMonth & "月" & theDay & "日" & "(" & theYoubi & ")"
set theText2 to theYear & "-" & theMM & "-" & theDD & " (" & theWDY & ")"
set theText3 to theYY & theMM & theDD
set theText4 to theYY & theMM & theDD & "_" & theHHMM
set theText5 to theGengouYear & "年" & theMonth & "月" & theDay & "日" & "(" & theYoubi & ")"
set chosenText to choose from list {theText1, theText2, theText3, theText4, theText5} with title "今日の日付をクリップボードにコピーする" default items theText1
if chosenText is not false then set the clipboard to chosenText as text
on zeroPrefix(txt)
if the length of txt = 1 then
set txt to "0" & txt
else
set txt to txt as text
end if
end zeroPrefix