Date&Time

経過時間


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#
005# com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "AppKit"
010use framework "UniformTypeIdentifiers"
011use scripting additions
012
013property refMe : a reference to current application
014
015##開始時間 スタートタイム
016set ocidStartTime to refMe's NSDate's |date|()
017
018
019repeat 10 times
020  log "経過時間: " & doGetTimeInderval(ocidStartTime)
021  
022  delay 1
023end repeat
024
025################################
026##経過時間計算
027################################
028to doGetTimeInderval(argStartTime)
029  #今の時間
030  set ocidEndTime to refMe's NSDate's |date|()
031  #渡されたスタート時間からの間隔を取得
032  set numIntervalSec to ocidEndTime's timeIntervalSinceDate:(argStartTime)
033  #戻り値が秒数値なので時間にする
034  set numH to (numIntervalSec / 3600) as integer
035  set numM to ((numIntervalSec - (numH * 3600)) / 60) as integer
036  set numS to (numIntervalSec - (numH * 3600) - (numM * 60)) as integer
037  #2桁テキストにして
038  set appFormatter to refMe's NSNumberFormatter's alloc()'s init()
039  appFormatter's setMinimumIntegerDigits:(2)
040  appFormatter's setPaddingCharacter:("0")
041  appFormatter's setPaddingPosition:(refMe's NSNumberFormatterPadBeforePrefix)
042  set strH to (appFormatter's stringFromNumber:(numH)) as text
043  set strM to (appFormatter's stringFromNumber:(numM)) as text
044  set strS to (appFormatter's stringFromNumber:(numS)) as text
045  #戻り値用整形
046  set strInterval to (strH & ":" & strM & ":" & strS) as text
047  return strInterval
048end doGetTimeInderval
049
AppleScriptで生成しました

|

[swift]DatePicker(日付選択画面)の呼び出し




ダウンロード - datepicker.zip



20240722030422_1100x790


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003# 日付ピッカーswift
004# 初回起動時に時間がかかる
005# swiftファイルが必要です
006(*
007こちらからダウンロードして試してください
008https://quicktimer.cocolog-nifty.com/icefloe/files/datepicker.zip
009*)
010# com.cocolog-nifty.quicktimer.icefloe
011----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
012use AppleScript version "2.8"
013use framework "Foundation"
014use framework "AppKit"
015use scripting additions
016
017#このファイルのパス
018set aliasPathToMe to (path to me) as alias
019tell application "Finder"
020  #コンテナ
021  set aliasContainerDirPath to (container of aliasPathToMe) as alias
022  #Swift格納先
023  set aliasBinDirPath to (folder "bin" of folder aliasContainerDirPath) as alias
024  #Swiftパス
025  set aliasSwiftPath to (file "launchDatePicker.swift" of folder aliasBinDirPath) as alias
026end tell
027#パス
028set strSwiftPath to (POSIX path of aliasSwiftPath) as text
029#コマンド整形 zsh指定
030set strCommandText to ("/bin/zsh -c '" & strSwiftPath & "'") as text
031log strCommandText
032try
033  #コマンド実行
034  set strResponse to (do shell script strCommandText) as text
035end try
036#戻り値がfalse=日付を選択しなかった場合
037#戻り値はbool値なんだけどAs textしているのでTextで比較
038if strResponse is "false" then
039#戻り値falseの場合は今日の日付を入れる
040  set strResponse to doGetDateNo("yyyyMMDD")
041end if
042
043
044##############################
045#####ダイアログ
046##############################
047tell current application
048  set strName to name as text
049end tell
050if strName is "osascript" then
051  tell application "Finder"
052    activate
053  end tell
054else
055  tell current application
056    activate
057  end tell
058end if
059set aliasIconPath to (POSIX file "/System/Applications/Clock.app/Contents/Resources/AppIcon.icns") as alias
060try
061  set recordResult to (display dialog strResponse with title "戻り値です" default answer strResponse buttons {"クリップボードにコピー", "終了", "再実行"} default button "再実行" cancel button "終了" giving up after 20 with icon aliasIconPath without hidden answer) as record
062on error
063  return "エラーしました"
064end try
065if (gave up of recordResult) is true then
066  return "時間切れです"
067end if
068##############################
069#####自分自身を再実行
070##############################
071if button returned of recordResult is "再実行" then
072  tell application "Finder"
073    set aliasPathToMe to (path to me) as alias
074  end tell
075  run script aliasPathToMe with parameters "再実行"
076end if
077##############################
078#####値のコピー
079##############################
080if button returned of recordResult is "クリップボードにコピー" then
081  try
082    set strText to text returned of recordResult as text
083    ####ペーストボード宣言
084    set appPasteboard to refMe's NSPasteboard's generalPasteboard()
085    set ocidText to (refMe's NSString's stringWithString:(strText))
086    appPasteboard's clearContents()
087    appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
088  on error
089    tell application "Finder"
090      set the clipboard to strText as text
091    end tell
092  end try
093end if
094
095
096return 0
097
098
099
100##############################
101### 今の日付日間 テキスト
102##############################
103to doGetDateNo(argDateFormat)
104  ####日付情報の取得
105  set ocidDate to current application's NSDate's |date|()
106  ###日付のフォーマットを定義
107  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
108  set ocidLocale to current application's NSLocale's localeWithLocaleIdentifier:("ja_JP_POSIX")
109  ocidNSDateFormatter's setLocale:(ocidLocale)
110  set ocidTimeZone to current application's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo")
111  ocidNSDateFormatter's setTimeZone:(ocidTimeZone)
112  ocidNSDateFormatter's setDateFormat:(argDateFormat)
113  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:(ocidDate)
114  set strDateAndTime to ocidDateAndTime as text
115  return strDateAndTime
116end doGetDateNo
AppleScriptで生成しました

|

NSURLCreationDateKey NSURLContentModificationDateKey ファイルの作成日と修正日のテキスト形式での取得


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#
005#com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "UniformTypeIdentifiers"
010use framework "AppKit"
011use scripting additions
012
013property refMe : a reference to current application
014set appFileManager to refMe's NSFileManager's defaultManager()
015
016
017################################
018#ダイアログ
019set strName to (name of current application) as text
020if strName is "osascript" then
021  tell application "Finder" to activate
022else
023  tell current application to activate
024end if
025
026set appFileManager to refMe's NSFileManager's defaultManager()
027set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
028set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
029set aliasDesktopDirPath to (ocidDesktopDirPathURL's absoluteURL()) as alias
030#
031set listUTI to {"public.item"}
032set strMes to ("ファイルを選んでください") as text
033set strPrompt to ("ファイルを選んでください") as text
034try
035  set listAliasFilePath to (choose file strMes with prompt strPrompt default location aliasDesktopDirPath of type listUTI with invisibles, multiple selections allowed and showing package contents) as list
036on error
037  log "エラーしました"
038  return "エラーしました"
039end try
040if listAliasFilePath is {} then
041  return "選んでください"
042end if
043################################
044#ファイルの数だけ繰り返し
045repeat with itemAliasFilePath in listAliasFilePath
046  ##########
047  #パス
048  set aliasFilePath to itemAliasFilePath as alias
049  set strFilePath to (POSIX path of aliasFilePath) as text
050  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
051  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
052  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
053  
054  ##########
055  #NSURLContentModificationDateKey
056  set listResponse to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentModificationDateKey) |error| :(reference))
057  if (item 1 of listResponse) is true then
058    set ocidModificationDate to (item 2 of listResponse)
059    log ocidModificationDate as date
060  else if (item 1 of listResponse) is false then
061    set strErrorNO to (item 3 of listDone)'s code() as text
062    set strErrorMes to (item 3 of listDone)'s localizedDescription() as text
063    refMe's NSLog("■:" & strErrorNO & strErrorMes)
064    return "エラーしました" & strErrorNO & strErrorMes
065  end if
066  ##########
067  #NSURLCreationDateKey
068  set listResponse to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLCreationDateKey) |error| :(reference))
069  if (item 1 of listResponse) is true then
070    set ocidCreationDateDate to (item 2 of listResponse)
071    log ocidCreationDateDate as date
072  else if (item 1 of listResponse) is false then
073    set strErrorNO to (item 3 of listDone)'s code() as text
074    set strErrorMes to (item 3 of listDone)'s localizedDescription() as text
075    refMe's NSLog("■:" & strErrorNO & strErrorMes)
076    return "エラーしました" & strErrorNO & strErrorMes
077  end if
078  
079  ####################
080  #カレンダーの仕様を設定
081  set ocidCalendarID to (refMe's NSCalendarIdentifierGregorian)
082  set ocidCalendar to (refMe's NSCalendar's alloc()'s initWithCalendarIdentifier:(ocidCalendarID))
083  set ocidTimezoneJP to (refMe's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo"))
084  set ocidLocaleJP to (refMe's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP_POSIX"))
085  #カレンダー初期化
086  set ocidFormatter to refMe's NSDateFormatter's alloc()'s init()
087  (ocidFormatter's setCalendar:(ocidCalendar))
088  (ocidFormatter's setTimeZone:(ocidTimezoneJP))
089  (ocidFormatter's setLocale:(ocidLocaleJP))
090  (ocidFormatter's setDateStyle:(refMe's NSDateFormatterFullStyle))
091  (ocidFormatter's setDateFormat:("yyyyMMdd-hhmmss"))
092  
093  #NSURLContentModificationDateKey
094  set ocidCreationDateDateStr to (ocidFormatter's stringFromDate:(ocidCreationDateDate))
095  set strCreationDateDate to ocidCreationDateDateStr as text
096  log strCreationDateDate
097  
098  #NSURLContentModificationDateKey
099  set ocidModificationDateStr to (ocidFormatter's stringFromDate:(ocidModificationDate))
100  set strModificationDate to ocidModificationDateStr as text
101  log strModificationDate
102  
103  log (ocidCalendar's component:(refMe's NSCalendarUnitYear) fromDate:(ocidCreationDateDate))
104  
105  
106  return
107  
108end repeat
109
110
111
112
AppleScriptで生成しました

|

[dateWithTimeIntervalSinceNow]昨日の今


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#
005#com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use scripting additions
010property refMe : a reference to current application
011
012
013##########
014#カレンダー
015set ocidCalendarID to (refMe's NSCalendarIdentifierGregorian)
016set ocidCalendar to (refMe's NSCalendar's alloc()'s initWithCalendarIdentifier:(ocidCalendarID))
017set ocidTimezoneJP to (refMe's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo"))
018set ocidLocaleJP to (refMe's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP_POSIX"))
019#今
020set ocidDate to refMe's NSDate's |date|()
021set ocidIntervalt to (refMe's NSDate's dateWithTimeIntervalSinceNow:(-86400))
022#昨日
023set ocidFormatter to refMe's NSDateFormatter's alloc()'s init()
024(ocidFormatter's setCalendar:(ocidCalendar))
025(ocidFormatter's setTimeZone:(ocidTimezoneJP))
026(ocidFormatter's setLocale:(ocidLocaleJP))
027(ocidFormatter's setDateStyle:(refMe's NSDateFormatterFullStyle))
028(ocidFormatter's setDateFormat:("yyyyMMdd"))
029
030set ocidDateAndTime to (ocidFormatter's stringFromDate:(ocidIntervalt))
031set strDateAndTime to ocidDateAndTime as text
032
033
034log ocidDate as date
035log ocidIntervalt as date
036log strDateAndTime as text
AppleScriptで生成しました

|

合字の日付を作成


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003# 月と日を合字で戻します
004#  com.cocolog-nifty.quicktimer.icefloe
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use framework "Foundation"
008use scripting additions
009
010log  doGetDateNo()
011
012
013
014################################
015# 日付 doGetDateNo()
016################################
017to doGetDateNo()
018  #戻す日付テキスト
019  set ocidRetuenString to current application's NSMutableString's alloc()'s initWithCapacity:(0)
020  ###今日
021  set ocidDate to (current application's NSDate's |date|())
022  ###フォーマット初期化
023  set ocidFormatterJP to current application's NSDateFormatter's alloc()'s init()
024  ###日本のカレンダー
025  set ocidCalendarID to (current application's NSCalendarIdentifierJapanese)
026  set ocidCalendarJP to current application's NSCalendar's alloc()'s initWithCalendarIdentifier:(ocidCalendarID)
027  ###東京タイムゾーン
028  set ocidTimezoneJP to current application's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo")
029  ###日本語
030  set ocidLocaleJP to current application's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP_POSIX")
031  ###フォーマットをセット(年号)
032  ocidFormatterJP's setTimeZone:(ocidTimezoneJP)
033  ocidFormatterJP's setLocale:(ocidLocaleJP)
034  ocidFormatterJP's setCalendar:(ocidCalendarJP)
035  ocidFormatterJP's setDateStyle:(current application's NSDateFormatterFullStyle)
036  set strDateFormat to (" ㋿y年")
037  ocidFormatterJP's setDateFormat:(strDateFormat)
038  set ocidDateStringEra to ocidFormatterJP's stringFromDate:(ocidDate)
039  # ocidRetuenString's appendString:(ocidDateStringEra)
040  ###フォマットから月合字を取得(使わない)
041  set recordMonth to {|01月|:"㋀", |02月|:"㋁", |03月|:"㋂", |04月|:"㋃", |05月|:"㋄", |06月|:"㋅", |07月|:"㋆", |08月|:"㋇", |09月|:"㋈", |10月|:"㋉", |11月|:"㋊", |12月|:"㋋"} as record
042  set ocidMonthDict to current application's NSMutableDictionary's alloc()'s initWithDictionary:(recordMonth)
043  set strDateFormat to ("MM月")
044  ocidFormatterJP's setDateFormat:(strDateFormat)
045  set ocidDateStringMonth to ocidFormatterJP's stringFromDate:(ocidDate)
046  set ocidMonthValue to ocidMonthDict's valueForKey:(ocidDateStringMonth)
047  ocidRetuenString's appendString:(ocidMonthValue)
048  ##フォーマットから日付を取得(使わない)
049  set recordDate to {|01|:"㏠", |02|:"㏡", |03|:"㏢", |04|:"㏣", |05|:"㏤", |06|:"㏥", |07|:"㏦", |08|:"㏧", |09|:"㏨", |10|:"㏩", |11|:"㏪", |12|:"㏫", |13|:"㏬", |14|:"㏭", |15|:"㏮", |16|:"㏯", |17|:"㏰", |18|:"㏱", |19|:"㏲", |20|:"㏳", |21|:"㏴", |22|:"㏵", |23|:"㏶", |24|:"㏷", |25|:"㏸", |26|:"㏹", |27|:"㏺", |28|:"㏻", |29|:"㏼", |30|:"㏽", |31|:"㏾"} as record
050  set ocidDateDict to current application's NSMutableDictionary's alloc()'s initWithDictionary:(recordDate)
051  set strDateFormat to ("dd")
052  ocidFormatterJP's setDateFormat:(strDateFormat)
053  set ocidDateStringDate to ocidFormatterJP's stringFromDate:(ocidDate)
054  set ocidDateValue to ocidDateDict's valueForKey:(ocidDateStringDate)
055  ocidRetuenString's appendString:(ocidDateValue)
056  #
057  set strDateAndTime to ((ocidRetuenString as text)) as text
058  ###テキストで戻す
059  return strDateAndTime
060end doGetDateNo
AppleScriptで生成しました

|

経過時間を計算する


【スクリプトエディタで開く】|


##何秒毎にカウントするか?
set numInterval to 2 as integer

###何になったらリピート終了するのか?
##リストは 時間、分、秒
set listExitTime to {0, 1, 11} as list
-->1分11秒超えたらリピートを抜けます


##初期値
set listTime to {0, 0, 0} as list
##繰り返し
repeat
  ###スタートタイム
  set strStartTime to doHMSms(listTime)
  log "経過時間 : " & strStartTime
  ##指定秒数待つ
  delay numInterval
  ##まず秒が加算されるといくつになるか?
  set numChkDigUp to (item 3 of listTime) + numInterval
  ###↑この結果が59より大きければ繰り上がる
  if numChkDigUp ≥ 60 then
    set (item 3 of listTime) to numChkDigUp - 60
    if (item 2 of listTime) = 59 then
      set (item 2 of listTime) to 0
      set (item 1 of listTime) to (item 1 of listTime)
    else
      set (item 2 of listTime) to (item 2 of listTime) + 1
    end if
  else
    set (item 3 of listTime) to (item 3 of listTime) + numInterval
  end if
  set strEndTime to doHMSms(listTime)
  if (item 1 of listTime) ≥ (item 1 of listExitTime) then
    if (item 2 of listTime) ≥ (item 2 of listExitTime) then
      if (item 3 of listTime) ≥ (item 3 of listExitTime) then
        ####エンドタイム
        log "経過時間 : " & strEndTime
        exit repeat
      end if
    end if
  end if
end repeat


###時間表示
on doHMSms(listTime)
  set strH to item 1 of listTime
  set strM to item 2 of listTime
  set strS to item 3 of listTime
return doPadding2Dig(strH) & ":" & doPadding2Dig(strM) & ":" & doPadding2Dig(strS)
end doHMSms

###2桁ゼロパディング
on doPadding2Dig(numNO)
  set strNO to ("0" & numNO) as text
return text -2 thru -1 of strNO
end doPadding2Dig


|

[dateWithTimeIntervalSinceNow]明日(24時間後的な意味で)


【スクリプトエディタで開く】|

#!/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

log doGetNextDateNo({"yyyyMMdd", 1})

################################
# 明日の日付 doGetDateNo(argDateFormat,argCalendarNO)
# argCalendarNO 1 NSCalendarIdentifierGregorian 西暦
# argCalendarNO 2 NSCalendarIdentifierJapanese 和暦
################################
to doGetNextDateNo({argDateFormat, argCalendarNO})
  ##渡された値をテキストで確定させて
  set strDateFormat to argDateFormat as text
  set intCalendarNO to argCalendarNO as integer
  ###日付情報の取得
  set ocidDate to current application's NSDate's |date|()
  set ocidIntervalt to current application's NSDate's dateWithTimeIntervalSinceNow:(86400)
  ###日付のフォーマットを定義(日本語)
  set ocidFormatterJP to current application's NSDateFormatter's alloc()'s init()
  ###和暦 西暦 カレンダー分岐
  if intCalendarNO = 1 then
    set ocidCalendarID to (current application's NSCalendarIdentifierGregorian)
  else if intCalendarNO = 2 then
    set ocidCalendarID to (current application's NSCalendarIdentifierJapanese)
  else
    set ocidCalendarID to (current application's NSCalendarIdentifierISO8601)
  end if
  set ocidCalendarJP to current application's NSCalendar's alloc()'s initWithCalendarIdentifier:(ocidCalendarID)
  set ocidTimezoneJP to current application's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo")
  set ocidLocaleJP to current application's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP_POSIX")
  ###設定
ocidFormatterJP's setTimeZone:(ocidTimezoneJP)
ocidFormatterJP's setLocale:(ocidLocaleJP)
ocidFormatterJP's setCalendar:(ocidCalendarJP)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterNoStyle)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterShortStyle)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterMediumStyle)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterLongStyle)
ocidFormatterJP's setDateStyle:(current application's NSDateFormatterFullStyle)
  ###渡された値でフォーマット定義
ocidFormatterJP's setDateFormat:(strDateFormat)
  ###フォーマット適応
  set ocidDateAndTime to ocidFormatterJP's stringFromDate:(ocidIntervalt)
  ###テキストで戻す
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetNextDateNo
return


|

[ShortCuts]日付をクリップボードに(ショートカット用)


【スクリプトエディタで開く】|

#!/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



|

日付の取得 ISO 8601形式


【スクリプトエディタで開く】|

#!/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 scripting additions
property refMe : a reference to current application


log doGetDateNo("yyyy-MM-dd'T'HH:mm:ss'Z'")

##############################
### 今の日付日間 テキスト
##############################
to doGetDateNo(argDateFormat)
  ####日付情報の取得
  set ocidDate to current application's NSDate's |date|()
  ###日付のフォーマットを定義
  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
  set ocidTimeZone to refMe's NSTimeZone's alloc()'s initWithName:"Asia/Tokyo"
ocidNSDateFormatter's setTimeZone:(ocidTimeZone)
ocidNSDateFormatter's setDateFormat:(argDateFormat)
  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo

|

テキストから日付データを取得する


【スクリプトエディタで開く】|

#!/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 scripting additions
property refMe : a reference to current application


set strDate to ("2023-12-24T00:00:01Z") as text
set strDateFormat to ("yyyy-MM-dd'T'HH:mm:ss'Z'") as text

set ocidDateData to doGetText2Date({strDate, strDateFormat})
log ocidDateData as date




##############################
### テキストから時間
##############################
to doGetText2Date({argDateText, argDateFormat})
  ###日付のフォーマットを定義
  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
  set ocidTimeZone to refMe's NSTimeZone's alloc()'s initWithName:"Asia/Tokyo"
ocidNSDateFormatter's setTimeZone:(ocidTimeZone)
ocidNSDateFormatter's setDateFormat:(argDateFormat)
  set ocidDateAndTime to ocidNSDateFormatter's dateFromString:(argDateText)
return ocidDateAndTime
end doGetText2Date

|

より以前の記事一覧

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager AppKit Apple AppleScript AppleScript do shell script AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript System Events AppleScript System Events Plist AppleScript Video Applications AppStore Archive Attributes Automator BackUp Barcode Barcode QR Barcode QR Decode Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome CIImage CityCode CloudStorage Color com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Device Diff Disk Dock DropBox Droplet eMail Encode % Encode Decode Encode UTF8 Error EXIFData ffmpeg File Finder Firefox Folder FolderAction Fonts GIF github Guide HTML HTML Entity Icon Illustrator Image Events Image2PDF ImageOptim iPhone iWork Javascript Jedit Json Label Leading Zero List locationd LRC lsappinfo LSSharedFileList m3u8 Mail MakePDF Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Mouse Music NetWork Notes NSArray NSArray Sort NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSColor NSColorList NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSPrintOperation NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth OneDrive PDF PDFAnnotation PDFAnnotationWidget PDFContext PDFDisplayBox PDFDocumentPermissions PDFImageRep PDFKit PDFnUP PDFOutline perl Photoshop PlistBuddy pluginkit postalcode PostScript prefPane Preview Python QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver SF Symbols character id SF Symbols Entity sips Skype Slack Sound Spotlight sqlite SRT StandardAdditions Swift System Settings TCC TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code VMware Fusion Wacom webarchive webp Wifi Windows XML XML EPUB XML OPML XML Plist XML RSS XML savedSearch XML SVG XML TTML XML webloc XML XMP YouTube zoom