人気ブログランキング | 話題のタグを見る
AppleScriptで今日の日付
AppleScriptで今日の日付を得るのはひじょうに簡単で、「(current date) as string」だけでいい。

display dialog (current date) as string

これを実行すると「2011年 1月 13日 木曜日 3:39:31 PM」みたいな文字列が表示される。
しかしながら、これを元に例えば「11.01.13-15.39」としたいとすると、
マジかよ、ってくらいにおおごとになる。こんな感じ。

property MonthNames : {January, February, March, April, May, June, July, August, September, October, November, December}

on DateToString(theDate)
set Y to ((year of theDate) - 2000) as text
set m to Num2Txt(Month2Num(month of theDate))
set D to Num2Txt(day of theDate)
set h to (time of theDate) div hours
set mi to (time of theDate) mod hours div minutes
set s to (time of theDate) mod minutes
if (count characters of (h as text)) is 1 then set h to "0" & (h as text)
if (count characters of (mi as text)) is 1 then set mi to "0" & (mi as text)
if (count characters of (s as text)) is 1 then set s to "0" & (s as text)
return Y & "." & m & "." & D & "-" & h & "." & mi & "." & s
end DateToString

on Num2Txt(NUM)
return text -2 thru -1 of ("0" & (NUM as text))
end Num2Txt

on Month2Num(m)
repeat with I from 1 to 12
if item I of MonthNames = m then return I
end repeat
end Month2Num

set aName to DateToString(current date)

tell application "Finder"
activate
make new folder at desktop with properties {name:aName}
end tell
個々の行の意味は、僕は理解してない。ただのコピペ。
なんでこんな簡単なことが、こんなに頑張った感じにしないとできない仕様なんだろうか。

「make new folder at desktop with properties {name:YY.MM.DD-HH.MNMN.SS}」

てな感じで出来てもよさそうなもんなのに。
(OS 8や9 の頃はもうちょい簡単だったような記憶がある)
by nobiox | 2011-01-13 16:49 | ├バカスクリプト |
<< 欧羅巴陰毛事情 | デスクトップピクチャを変更 - 3 >>