#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
###今日
set ocidDate to refMe's NSDate's |date|()
###フォーマット初期化日本語
set ocidFormatterJP to refMe's NSDateFormatter's alloc()'s init()
set ocidCalendarJP to refMe's NSCalendar's alloc()'s initWithCalendarIdentifier:(refMe's NSCalendarIdentifierJapanese)
set ocidTimezoneJP to refMe's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo")
set ocidLocaleJP to refMe's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP_POSIX")
###フォーマット初期化通常
set ocidFormatter to refMe's NSDateFormatter's alloc()'s init()
ocidFormatter's setTimeStyle:(refMe's NSDateFormatterNoStyle)
##ダイアログで選択するためのリスト
set ocidArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
##フォーマットNSDateFormatterLongStyle
ocidFormatter's setDateStyle:(refMe's NSDateFormatterLongStyle)
set ocidDateString to ocidFormatter's stringFromDate:(ocidDate)
ocidArrayM's addObject:(ocidDateString)
##フォーマットNSDateFormatterShortStyle
ocidFormatter's setDateStyle:(refMe's NSDateFormatterShortStyle)
set ocidDateString to ocidFormatter's stringFromDate:(ocidDate)
ocidArrayM's addObject:(ocidDateString)
##フォーマット テキスト
ocidFormatter's setDateFormat:("yyyyMMdd")
set ocidDateString to ocidFormatter's stringFromDate:(ocidDate)
ocidArrayM's addObject:(ocidDateString)
##フォーマット テキスト
ocidFormatter's setDateFormat:("yyyy年MM月dd日EEEE")
set ocidDateString to ocidFormatter's stringFromDate:(ocidDate)
ocidArrayM's addObject:(ocidDateString)
##フォーマット テキスト
ocidFormatter's setDateFormat:("yyyy-MM-dd")
set ocidDateString to ocidFormatter's stringFromDate:(ocidDate)
ocidArrayM's addObject:(ocidDateString)
##フォーマット テキスト
ocidFormatter's setDateFormat:("yyyy-MM-dd'T'HH:mm:ss'Z'")
set ocidDateString to ocidFormatter's stringFromDate:(ocidDate)
ocidArrayM's addObject:(ocidDateString)
###フォーマット 和暦用
ocidFormatterJP's setTimeZone:(ocidTimezoneJP)
ocidFormatterJP's setLocale:(ocidLocaleJP)
ocidFormatterJP's setCalendar:(ocidCalendarJP)
ocidFormatterJP's setDateFormat:("Gyy")
###今日の日付にフォーマットを適応
set ocidDateStringEra to ocidFormatterJP's stringFromDate:(ocidDate)
ocidFormatterJP's setDateFormat:("年MM月dd日")
set ocidDateString to ocidFormatterJP's stringFromDate:(ocidDate)
ocidArrayM's addObject:((ocidDateStringEra as text) & (ocidDateString as text))
###フォーマット 和暦用
ocidFormatterJP's setTimeZone:(ocidTimezoneJP)
ocidFormatterJP's setLocale:(ocidLocaleJP)
ocidFormatterJP's setCalendar:(ocidCalendarJP)
ocidFormatterJP's setDateFormat:("Gyy")
set ocidDateStringEra to ocidFormatterJP's stringFromDate:(ocidDate)
ocidFormatterJP's setDateFormat:("年MM月dd日EEEE")
set ocidDateString to ocidFormatterJP's stringFromDate:(ocidDate)
ocidArrayM's addObject:((ocidDateStringEra as text) & (ocidDateString as text))
###ダイアログ用にリストにする
set listDate to ocidArrayM as list
#####ダイアログ
try
###ダイアログを前面に出す
tell current application
set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
tell application "Finder"
activate
end tell
else
tell current application
activate
end tell
end if
set listResponse to (choose from list listDate with title "選んでください" with prompt "クリップボードにコピーします" default items (item 1 of listDate) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしました"
else
set strText to (item 1 of listResponse) as text
try
####ペーストボード宣言
set appPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
on error
tell application "Finder"
set the clipboard to strText as text
end tell
end try
end if