[AppleScript]英語環境でのcurrent dateでの戻り値の処理
【スクリプトエディタで開く】 |
current date.scpt.scpt | ソース |
|---|
| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- |
| 004 | (* |
| 005 | 英語環境用です |
| 006 | 日本語環境では、current dateの戻り値が異なるため使えません |
| 007 |
|
| 008 |
|
| 009 |
|
| 010 | com.cocolog-nifty.quicktimer.icefloe *) |
| 011 | ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- |
| 012 | use AppleScript version "2.8" |
| 013 | use scripting additions |
| 014 |
|
| 015 | set aliasPrefDir to (path to preferences from user domain) as alias |
| 016 | tell application "Finder" |
| 017 | set aliasGlobalPreferences to (file ".GlobalPreferences.plist" of folder aliasPrefDir) as alias |
| 018 | end tell |
| 019 | set strGlobalPreferences to (POSIX path of aliasGlobalPreferences) as string |
| 020 |
|
| 021 | tell application "System Events" |
| 022 | tell property list file strGlobalPreferences |
| 023 | try |
| 024 | set bool24H to (value of property list item "AppleICUForce24HourTime") as boolean |
| 025 | on error strErrMsg number numErrNo |
| 026 | set bool24H to true as boolean |
| 027 | end try |
| 028 | end tell |
| 029 | end tell |
| 030 |
|
| 031 | set strDate to (current date) as string |
| 032 |
|
| 033 | if bool24H is false then |
| 034 | #NARROW NO-BREAK SPACE U+202F |
| 035 | set strNarrowNoBreakSpace to (character id 8239) as string |
| 036 | #SPACE U+0020 |
| 037 | set strSpace to (character id 32) as string |
| 038 | #区切り文字でリストにして List it with a separed character |
| 039 | set strDelim to AppleScript's text item delimiters |
| 040 | set AppleScript's text item delimiters to strNarrowNoBreakSpace |
| 041 | set listDate to (every text item of strDate) as list |
| 042 | #AMPMはここで取得 |
| 043 | set strMeridiem to (last item of listDate) as string |
| 044 | #スペースで置換 Replace with space |
| 045 | set AppleScript's text item delimiters to strSpace |
| 046 | set strDate to listDate as string |
| 047 | set listDate to (every text item of strDate) as list |
| 048 | set strTime to (item ((count of listDate) - 1) of listDate) as string |
| 049 | set AppleScript's text item delimiters to strDelim |
| 050 | else if bool24H is true then |
| 051 | set strDelim to AppleScript's text item delimiters |
| 052 | set AppleScript's text item delimiters to space |
| 053 | set listDate to (every text item of strDate) as list |
| 054 | set strTime to (last item of listDate) as string |
| 055 | set AppleScript's text item delimiters to ":" |
| 056 | set listTime to (every text item of strTime) as list |
| 057 | set numH to (first item of listTime) as integer |
| 058 | if numH ≥ 12 then |
| 059 | set strMeridiem to ("PM") as string |
| 060 | set strH to (numH - 12) as string |
| 061 | copy strH to first item of listTime |
| 062 | else |
| 063 | set strMeridiem to ("AM") as string |
| 064 | end if |
| 065 | set strTime to listTime as string |
| 066 | set AppleScript's text item delimiters to strDelim |
| 067 | end if |
| 068 |
|
| 069 | return (strMeridiem & " " & strTime) as string |
| AppleScriptで生成しました |
|---|