2番煎じMEMO

「どこかで見たことあるよ」的な内容を中心に  Mac のことなど いろいろ

今日の日付をクリップボードにコピーするAppleScript その2

先日書いた「今日の日付をクリップボードにコピーするAppleScript」をもう少し実用的に、且つ、AppleScript の書き方を思い出そうと、いろいろ修正してみました。

 

今度のものは一度いろんな様式の日付の候補リストを表示し、その中から選択したものをクリップボードにコピーするようになってます。

f:id:wakabamark_mac:20180309001053j:plain

以下、ソース。

 

-- クリップボードに今日の日付をコピーする -その2- 2018-03-08 (Thu)
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