AppleScript名:NSCountedSetでNSDictionaryの登場頻度集計 v2 |
— Created 2015-09-14 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aRecList to {{aName:"Piyomaru", aFavorite:"Sleeping"}, {aName:"Piyoko", aFavorite:"TV"}, {aName:"Piyomaru", aFavorite:"Sleeping"}} set aCountedList to countEachRecord(aRecList) –> {{aCount:1, aData:{aName:"Piyoko", aFavorite:"TV"}}, {aCount:2, aData:{aName:"Piyomaru", aFavorite:"Sleeping"}}} on countEachRecord(aRecList) set theCountedSet to current application’s NSCountedSet’s |set|() repeat with i in aRecList set j to contents of i (theCountedSet’s addObject:j) end repeat set theEnumerator to theCountedSet’s objectEnumerator() set anArray to current application’s NSMutableArray’s alloc()’s init() repeat set aDict to current application’s NSMutableDictionary’s alloc()’s init() set aValue to theEnumerator’s nextObject() if aValue is missing value then exit repeat set aCount to theCountedSet’s countForObject:aValue aDict’s setObject:aCount forKey:"aCount" aDict’s setObject:aValue forKey:"aData" anArray’s addObject:aDict end repeat return anArray as list of string or string end countEachRecord |
タグ: 10.11savvy
NSDictionaryのObjectEnumlator, KeyEnumlatorで値列挙
AppleScript名:NSDictionaryのObjectEnumlator, KeyEnumlatorで値列挙 |
— Created 2017-07-30 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aRec to {aaa:1, bbb:2, ccc:3} set aDict to current application’s NSMutableDictionary’s dictionaryWithDictionary:aRec set dEnum to aDict’s objectEnumerator() repeat set aVal to dEnum’s nextObject() if aVal = missing value then exit repeat log aVal (* 15:40:47.098 (* (NSNumber) 1 *) 15:40:47.099 (* (NSNumber) 2 *) 15:40:47.099 (* (NSNumber) 3 *) *) end repeat set kEnum to aDict’s keyEnumerator() repeat set aVal to kEnum’s nextObject() if aVal = missing value then exit repeat log aVal (* 15:50:52.276 (* (NSString) "aaa" *) 15:50:52.276 (* (NSString) "bbb" *) 15:50:52.276 (* (NSString) "ccc" *) *) end repeat |
レコードのうち、最大の値を持つKeyを返す
AppleScript名:レコードのうち、最大の値を持つKeyを返す |
— Created 2016-12-14 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aDict to current application’s NSDictionary’s dictionaryWithDictionary:{sadness:0.01133416, anger:1.03975857E-4, happiness:2.90919736E-4, fear:2.28432211E-4, neutral:0.9830475, contempt:2.4698046E-4, disgust:1.02946949E-4, surprise:0.00464509334} set aMacKey to retMaxValueKey(aDict) of me –> "neutral" on retMaxValueKey(aDict) set aValList to aDict’s allValues() set maxVal to (sort1DNumList(aValList, false) of me)’s firstObject() set keyList to (aDict’s allKeys()) as list repeat with i in keyList set j to contents of i set aTmp to (aDict’s valueForKey:j) set aRes to compareNumerically(maxVal, aTmp) of me if aRes = true then return j end repeat return false end retMaxValueKey –Numerical Strings Compare on compareNumerically(aText as text, bText as text) set aStr to current application’s NSString’s stringWithString:aText return (aStr’s compare:bText options:(current application’s NSNumericSearch)) = current application’s NSOrderedSame end compareNumerically –1D List(数値)をsort / ascOrderがtrueだと昇順ソート、falseだと降順ソート on sort1DNumList(theList, aBool) set theSet to current application’s NSSet’s setWithArray:theList set theDescriptor to current application’s NSSortDescriptor’s sortDescriptorWithKey:(missing value) ascending:aBool set sortedList to theSet’s sortedArrayUsingDescriptors:{theDescriptor} return (sortedList) end sort1DNumList |
レコードの値をクリア v2
AppleScript名:レコードの値をクリア v2 |
— Created 2016-06-06 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.5" use scripting additions use framework "Foundation" set initVal to "" set aaaaaaaRec to {aaa:"111", bbb:2.1234, ccc:-1} set bRec to clearRecordValues(aaaaaaaRec) of me –> {aaa:"", bbb:0, ccc:0} on clearRecordValues(paramRec) set aDic to current application’s NSMutableDictionary’s dictionaryWithDictionary:paramRec set keyList to (aDic’s allKeys() as list) set valList to (aDic’s allValues() as list) repeat with i from 1 to (length of keyList) set aKey to contents of item i of keyList set tmpVal to contents of item i of valList set aClass to class of tmpVal –もともと入っていたデータの型を見て、クリア時の初期値を判定 if aClass is in {number, integer, real} then set initVal to 0 else if aClass is in {string, text, Unicode text} then set initVal to "" else set initVal to missing value end if (aDic’s setValue:initVal forKey:aKey) end repeat return aDic as record end clearRecordValues |
YAMLのじっけん5
AppleScript名:YAMLのじっけん5 |
— Created 2017-02-16 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "YAML" –https://github.com/mirek/YAML.framework –YAMLの文字列からオブジェクトを生成する(1) set aYAMLstr to " — # お好みの映画、ブロック形式 – Casablanca – Spellbound – Notorious — # 買い物リスト、インライン形式、またはフロー形式 [milk, bread, eggs] " set aRes to retObjectFromYAMLString(aYAMLstr) of me log result –> {{"Casablanca", "Spellbound", "Notorious"}, {"milk", "bread", "eggs"}} –YAMLの文字列からオブジェクトを生成する(2) set aYAMLstr to " – {name: John Smith, age: 33} – name: Mary Smith age: 27 " set aRes to retObjectFromYAMLString(aYAMLstr) of me log result –> {{{name:"John Smith", age:"33"}, {name:"Mary Smith", age:"27"}}} –YAMLの文字列からオブジェクトを生成する(3) set aYAMLstr to " men: [John Smith, Bill Jones] women: – Mary Smith – Susan Williams" set aRes to retObjectFromYAMLString(aYAMLstr) of me log result –> {{men:{"John Smith", "Bill Jones"}, women:{"Mary Smith", "Susan Williams"}}} on retObjectFromYAMLString(aYAMLstr as string) set aStr to current application’s NSString’s stringWithString:aYAMLstr set aData to aStr’s dataUsingEncoding:(current application’s NSUTF8StringEncoding) set aData to current application’s YAMLSerialization’s objectsWithYAMLString:aStr options:(4096) |error|:(missing value) return aData as list of string or string end retObjectFromYAMLString on retYAMLStringFromObject(anObject) set aString to (current application’s YAMLSerialization’s createYAMLStringWithObject:anObject options:(1) |error|:(missing value)) as list of string or string return aString end retYAMLStringFromObject |
YAMLのじっけん4
AppleScript名:YAMLのじっけん4 |
— Created 2017-02-16 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "YAML" –https://github.com/mirek/YAML.framework –YAMLの文字列からオブジェクトを生成する set aYAMLstr to " – name: Smith email: smith@mail.com – name: Shelton email: shelton@mail.com – name: Kelly email: kelly@mail.com " set aRes to (retObjectFromYAMLString(aYAMLstr) of me) as list of string or string log result –> {{{name:"Smith", email:"smith@mail.com"}, {name:"Shelton", email:"shelton@mail.com"}, {name:"Kelly", email:"kelly@mail.com"}}} set bYAMLstr to " names: [Smith, Shelton, Kelly] emails: [smith@mail.com, shelton@mail.com, kelly@mail.com] " set bRes to retObjectFromYAMLString(bYAMLstr) of me log result –> {{names:{"Smith", "Shelton", "Kelly"}, emails:{"smith@mail.com", "shelton@mail.com", "kelly@mail.com"}}} –オブジェクト(list)からYAMLの文字列を生成する set bStr to retYAMLStringFromObject(bRes) log result (* "— – names: – Smith – Shelton – Kelly emails: – smith@mail.com – shelton@mail.com – kelly@mail.com … " *) on retObjectFromYAMLString(aYAMLstr as string) set aStr to current application’s NSString’s stringWithString:aYAMLstr set aData to aStr’s dataUsingEncoding:(current application’s NSUTF8StringEncoding) set aData to current application’s YAMLSerialization’s objectsWithYAMLString:aStr options:(4096) |error|:(missing value) return aData as list of string or string end retObjectFromYAMLString on retYAMLStringFromObject(anObject) set aString to (current application’s YAMLSerialization’s createYAMLStringWithObject:anObject options:(1) |error|:(missing value)) as list of string or string return aString end retYAMLStringFromObject |
YAMLのじっけん
AppleScript名:YAMLのじっけん |
— Created 2017-02-16 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "YAML" –https://github.com/mirek/YAML.framework –YAMLの文字列からオブジェクトを生成する set aYAMLstr to " items: – name: Foo – name: Bar " set aStr to current application’s NSString’s stringWithString:aYAMLstr set aData to aStr’s dataUsingEncoding:(current application’s NSUTF8StringEncoding) set aData to (current application’s YAMLSerialization’s objectsWithYAMLString:aStr options:(4096) |error|:(missing value)) as list of string or string log result –> {{items:{{name:"Foo"}, {name:"Bar"}}}} –オブジェクトからYAMLの文字列を取得する set aString to (current application’s YAMLSerialization’s createYAMLStringWithObject:aData options:(1) |error|:(missing value)) as string (* –> "— – items: – name: Foo – name: Bar …" *) |
JSONデータからのしぼりこみ
AppleScript名:JSONデータからのしぼりこみ |
— Created 2016-11-16 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Foundation" use scripting additions set theJSON to "{\"timeblocksDefs\": { \"normal\": { \"morning\": \"06-09\", \"day\": \"09-18\", \"primetime\": \"18-22\", \"nighttime\": \"22-06\" }, \"lateprime\": { \"morning\": \"06-09\", \"day\": \"09-19\", \"primetime\": \"19-23\", \"nighttime\": \"23-06\" } }} " set theDict to my convertJSONToDictionary:theJSON set theResult to (theDict’s valueForKeyPath:"timeblocksDefs.lateprime") — convert to AS equivalent set theResult to item 1 of ((current application’s NSArray’s arrayWithObject:theResult) as list) on convertJSONToDictionary:jsonString set aString to current application’s NSString’s stringWithString:jsonString set theData to aString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding) set {theDict, theError} to current application’s NSJSONSerialization’s JSONObjectWithData:theData options:0 |error|:(reference) if theDict is missing value then error (theError’s localizedDescription() as text) number -10000 return theDict end convertJSONToDictionary: |
指定URLのJSONをダウンロードしてRecordに変換 v2.1
AppleScript名:指定URLのJSONをダウンロードしてRecordに変換 v2.1 |
— Created 2016-02-06 by Takaaki Naganoya — Modified 2016-02-08 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" –東京電力電力供給状況API JSON URL(指定された日時の電力使用状況を返す) set a to downloadAndParseJSON("http://tepco-usage-api.appspot.com/2016/2/6/19.json") of me –> {forecast_peak_period:18, forecast_peak_usage:3670, capacity_updated:"2012-02-05 08:30:00", usage:3720, forecast_peak_updated:"2012-02-05 08:30:00", day:6, usage_updated:"2016-02-06 11:05:05", capacity:4484, saving:false, year:2016, month:2, capacity_peak_period:18, forecast:0, hour:19, entryfor:"2016-02-06 10:00:00"} –東京電力電力供給状況API JSON URL(指定された日の毎時の電力使用状況を、配列として返す) set b to downloadAndParseJSON("http://tepco-usage-api.appspot.com/2016/2/6.json") of me –> {{forecast_peak_period:18, forecast_peak_usage:3670, capacity_updated:"2012-02-05 08:30:00", usage:3081, forecast_peak_updated:"2012-02-05 08:30:00", day:6, usage_updated:"2016-02-05 16:05:06", capacity:4484, saving:false, year:2016, month:2, capacity_peak_period:18, forecast:0, hour:0, entryfor:"2016-02-05 15:00:00"}….…{forecast_peak_period:18, forecast_peak_usage:3670, capacity_updated:"2012-02-05 08:30:00", usage:3645, forecast_peak_updated:"2012-02-05 08:30:00", day:6, usage_updated:"2016-02-06 12:05:07", capacity:4484, saving:false, year:2016, month:2, capacity_peak_period:18, forecast:0, hour:20, entryfor:"2016-02-06 11:00:00"}} –東京電力電力供給状況API JSON URL(指定された月の毎日毎時の電力使用状況を、配列として返す) set c to downloadAndParseJSON("http://tepco-usage-api.appspot.com/2016/2.json") of me –> {{forecast_peak_period:18, forecast_peak_usage:4260, capacity_updated:"2012-01-31 23:30:00", usage:2901, forecast_peak_updated:"2012-01-31 23:30:00", day:1, usage_updated:"2016-01-31 16:05:04", capacity:4641, saving:false, year:2016, month:2, capacity_peak_period:18, forecast:0, hour:0, entryfor:"2016-01-31 15:00:00"}……{forecast_peak_period:18, forecast_peak_usage:3670, capacity_updated:"2012-02-05 08:30:00", usage:3645, forecast_peak_updated:"2012-02-05 08:30:00", day:6, usage_updated:"2016-02-06 12:05:07", capacity:4484, saving:false, year:2016, month:2, capacity_peak_period:18, forecast:0, hour:20, entryfor:"2016-02-06 11:00:00"}} on downloadAndParseJSON(aURL) set aRes to downloadDataFromWeb(aURL, 30) of me if aRes = false then return false –download error set jsonString to current application’s NSString’s stringWithString:aRes set jsonData to jsonString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding) set aJsonDict to current application’s NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value) set bRes to aJsonDict as list of string or string return bRes end downloadAndParseJSON on downloadDataFromWeb(aURL, timeOutSec) set aURL to current application’s |NSURL|’s alloc()’s initWithString:aURL set aReq to current application’s NSURLRequest’s alloc()’s initWithURL:aURL cachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:timeOutSec set urlRes to (current application’s NSURLConnection’s sendSynchronousRequest:aReq returningResponse:(missing value) |error|:(missing value)) if urlRes = missing value then return false –Download Error else set aVal to (current application’s NSString’s alloc()’s initWithData:urlRes encoding:(current application’s NSUTF8StringEncoding)) return aVal end if end downloadDataFromWeb |
現在のLocaleのIdentifier文字を取得する
AppleScript名:現在のLocaleのIdentifier文字を取得する.scpt |
use AppleScript version "2.7" use scripting additions use framework "Foundation" set aLoc to (current application’s NSLocale’s currentLocale()’s identifier()) as anything log aLoc –> "ja_JP" set aLoc to (current application’s NSLocale’s systemLocale()’s identifier()) as anything log aLoc –> (__NSCFLocale) <__NSCFLocale: 0x6180000f5480> set isoCountry to (current application’s NSLocale’s ISOCountryCodes()) as anything log isoCountry –> (NSArray) {"AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"} set isoCurrency to (current application’s NSLocale’s ISOCurrencyCodes()) as anything log isoCurrency –> {"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "AUD", "AWG", "AZM", "AZN", "BAD", "BAM", "BAN", "BBD", "BDT", "BEC", "BEF", "BEL", "BGL", "BGM", "BGN", "BGO", "BHD", "BIF", "BMD", "BND", "BOB", "BOL", "BOP", "BOV", "BRB", "BRC", "BRE", "BRL", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNX", "CNY", "COP", "COU", "CRC", "CSD", "CSK", "CUC", "CUP", "CVE", "CYP", "CZK", "DDM", "DEM", "DJF", "DKK", "DOP", "DZD", "ECS", "ECV", "EEK", "EGP", "EQE", "ERN", "ESA", "ESB", "ESP", "ETB", "EUR", "FIM", "FJD", "FKP", "FRF", "GBP", "GEK", "GEL", "GHC", "GHS", "GIP", "GMD", "GNF", "GNS", "GQE", "GRD", "GTQ", "GWE", "GWP", "GYD", "HKD", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "ILS", "INR", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LSM", "LTL", "LTT", "LUC", "LUF", "LUL", "LVL", "LVR", "LYD", "MAD", "MAF", "MCF", "MDC", "MDL", "MGA", "MGF", "MKD", "MKN", "MLF", "MMK", "MNT", "MOP", "MRO", "MTL", "MTP", "MUR", "MVP", "MVR", "MWK", "MXN", "MXP", "MXV", "MYR", "MZE", "MZM", "MZN", "NAD", "NGN", "NIC", "NIO", "NLG", "NOK", "NPR", "NZD", "OMR", "PAB", "PEI", "PEN", "PES", "PGK", "PHP", "PKR", "PLN", "PLZ", "PTE", "PYG", "QAR", "RHD", "ROL", "RON", "RSD", "RUB", "RUR", "RWF", "SAR", "SBD", "SCR", "SDD", "SDG", "SDP", "SEK", "SGD", "SHP", "SIT", "SKK", "SLL", "SOS", "SRD", "SRG", "SSP", "STD", "SUR", "SVC", "SYP", "SZL", "THB", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "TWD", "TZS", "UAH", "UAK", "UGS", "UGX", "USD", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "VND", "VNN", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XEU", "XFO", "XFU", "XOF", "XPD", "XPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWL", "ZWR", "ZWD"} set aveLoc to (current application’s NSLocale’s availableLocaleIdentifiers()) as anything log aveLoc –> {"eu", "hr_BA", "en_CM", "rw_RW", "en_SZ", "tk_Latn", "uz_Arab", "he_IL", "ar", "en_PN", "as", "en_NF", "rwk_TZ", "zh_Hant_TW", "gsw_LI", "th_TH", "ta_IN", "es_EA", "fr_GF", "ar_001", "en_RW", "tr_TR", "de_CH", "ee_TG", "en_NG", "fr_TG", "az", "fr_SC", "es_HN", "en_AG", "ru_KZ", "gsw", "dyo", "so_ET", "zh_Hant_MO", "de_BE", "km_KH", "my_MM", "mgh_MZ", "ee_GH", "es_EC", "kw_GB", "rm_CH", "en_ME", "nyn", "mk_MK", "bs_Cyrl_BA", "ar_MR", "en_BM", "ms_Arab", "en_AI", "gl_ES", "en_PR", "ha_Latn_GH", "ne_IN", "or_IN", "khq_ML", "en_MG", "pt_TL", "en_LC", "ta_SG", "jmc_TZ", "om_ET", "lv_LV", "es_US", "en_PT", "vai_Latn_LR", "to_TO", "en_NL", "cgg_UG", "ta", "en_MH", "iu_Cans_CA", "zu_ZA", "shi_Latn_MA", "brx_IN", "ar_KM", "en_AL", "te", "chr_US", "yo_BJ", "fr_VU", "pa", "tg", "ks_Arab", "kea", "te_IN", "th", "fr_RE", "ur_IN", "yo_NG", "ti", "guz_KE", "tk", "kl_GL", "ksf_CM", "mua_CM", "lag_TZ", "fr_TN", "es_PA", "pl_PL", "to", "hi_IN", "dje_NE", "es_GQ", "kok_IN", "pl", "tr", "bem", "ha", "ckb", "lg", "fr_GN", "en_PW", "en_NO", "nyn_UG", "sr_Latn_RS", "pa_Guru", "he", "swc_CD", "ug_Arab", "lu_CD", "mgo_CM", "sn_ZW", "en_BS", "ps_AF", "da", "ms_Latn_SG", "ps", "ln", "pt", "iu_Cans", "hi", "lo", "ebu", "de", "gu_IN", "seh", "en_CX", "en_ZM", "tzm_Latn_MA", "fr_HT", "fr_GP", "lt", "lu", "ln_CD", "vai_Latn", "el_GR", "lv", "en_KE", "sbp", "hr", "en_CY", "es_GT", "twq_NE", "zh_Hant_HK", "kln_KE", "fr_GQ", "chr", "hu", "es_UY", "fr_CA", "en_NR", "mer", "shi", "es_PE", "fr_SN", "bez", "sw_TZ", "kkj", "hy", "kk_Cyrl_KZ", "en_CZ", "teo_KE", "teo", "dz_BT", "ar_JO", "mer_KE", "khq", "ln_CF", "nn_NO", "en_MO", "ar_TD", "dz", "ses", "en_BW", "en_AS", "ar_IL", "ms_Latn_BN", "bo_CN", "nnh", "teo_UG", "hy_AM", "ln_CG", "sr_Latn_BA", "en_MP", "ksb_TZ", "ar_SA", "ar_LY", "en_AT", "so_KE", "fr_CD", "af_NA", "en_NU", "es_PH", "en_KI", "en_JE", "lkt", "en_AU", "fa_IR", "uz_Latn_UZ", "ky_Cyrl", "zh_Hans_CN", "ewo_CM", "fr_PF", "ca_IT", "en_BZ", "ar_KW", "pt_GW", "fr_FR", "am_ET", "en_VC", "fr_DJ", "fr_CF", "es_SV", "en_MS", "pt_ST", "ar_SD", "luy_KE", "swc", "de_LI", "fr_CG", "zh_Hans_SG", "en_MT", "ewo", "af_ZA", "om_KE", "nl_SR", "es_ES", "es_DO", "ar_IQ", "fr_CH", "nnh_CM", "es_419", "en_MU", "en_US_POSIX", "yav_CM", "luo_KE", "dua_CM", "et_EE", "en_IE", "ak_GH", "rwk", "es_CL", "kea_CV", "fr_CI", "fr_BE", "en_NZ", "ky_Cyrl_KG", "en_LR", "en_KN", "nb_SJ", "sg", "sr_Cyrl_RS", "ru_RU", "en_ZW", "sv_AX", "si", "ga_IE", "en_VG", "sk", "agq_CM", "fr_BF", "naq_NA", "sl", "en_MW", "mr_IN", "az_Latn", "en_LS", "de_AT", "ka", "sn", "sr_Latn_ME", "fr_NC", "so", "is_IS", "twq", "ig_NG", "sq", "fo_FO", "sr", "tzm", "ga", "om", "en_LT", "bas_CM", "ki", "nl_BE", "ar_QA", "sv", "kk", "sw", "es_CO", "az_Latn_AZ", "rn_BI", "or", "kl", "ca", "en_VI", "km", "kn", "en_LU", "fr_SY", "ar_TN", "en_JM", "fr_PM", "ko", "fr_NE", "fr_MA", "gl", "ru_MD", "saq_KE", "ks", "fr_CM", "gv_IM", "fr_BI", "en_LV", "ks_Arab_IN", "es_NI", "en_GB", "kw", "nl_SX", "dav_KE", "tr_CY", "ky", "en_UG", "tzm_Latn", "en_TC", "nus_SD", "ar_EG", "fr_BJ", "gu", "es_PR", "fr_RW", "sr_Cyrl_BA", "gv", "fr_MC", "cs", "bez_TZ", "es_CR", "asa_TZ", "ar_EH", "ms_Arab_BN", "mn_Cyrl", "sbp_TZ", "ha_Latn_NE", "lt_LT", "mfe", "en_GD", "cy", "ca_FR", "es_BO", "fr_BL", "bn_IN", "uz_Cyrl_UZ", "az_Cyrl", "en_IM", "sw_KE", "en_SB", "ur_PK", "pa_Arab", "haw_US", "ar_SO", "en_IN", "ha_Latn", "fil", "fr_MF", "en_WS", "es_CU", "ja_JP", "en_SC", "en_IO", "pt_PT", "en_HK", "en_GG", "fr_MG", "de_LU", "ms_Latn_MY", "tg_Cyrl", "en_SD", "shi_Tfng", "ln_AO", "ug_Arab_CN", "as_IN", "en_GH", "ro_RO", "jgo_CM", "dua", "en_UM", "en_SE", "kn_IN", "en_KY", "vun_TZ", "kln", "en_GI", "ca_ES", "rof", "pt_CV", "kok", "pt_BR", "ar_DJ", "zh", "fi_FI", "tg_Cyrl_TJ", "es_PY", "ar_SS", "mua", "sr_Cyrl_ME", "vai_Vaii_LR", "en_001", "xog_UG", "en_TK", "si_LK", "en_SG", "nl_NL", "vi", "sv_SE", "pt_AO", "fr_DZ", "ca_AD", "xog", "en_IS", "nb", "seh_MZ", "es_AR", "sk_SK", "en_SH", "ti_ER", "nd", "az_Cyrl_AZ", "zu", "ne", "nd_ZW", "el_CY", "en_IT", "nl_BQ", "da_GL", "ja", "rm", "fr_ML", "rn", "en_VU", "rof_TZ", "ro", "ebu_KE", "ru_KG", "en_SI", "sg_CF", "mfe_MU", "nl", "brx", "bs_Latn", "fa", "zgh_MA", "en_GM", "shi_Latn", "en_FI", "nn", "en_EE", "ru", "kam_KE", "vai_Vaii", "ar_ER", "ti_ET", "rw", "ff", "luo", "fa_AF", "ha_Latn_NG", "nl_CW", "en_HR", "en_FJ", "fi", "pt_MO", "be", "en_US", "en_TO", "en_SK", "bg", "ru_BY", "it_IT", "ml_IN", "gsw_CH", "fo", "sv_FI", "en_FK", "nus", "ta_LK", "vun", "sr_Latn", "fr", "en_SL", "bm", "ar_BH", "guz", "bn", "bo", "ar_SY", "lo_LA", "ne_NP", "uz_Latn", "be_BY", "es_IC", "sr_Latn_XK", "ar_MA", "pa_Guru_IN", "br", "luy", "kde_TZ", "bs", "hu_HU", "ar_AE", "en_HU", "zh_Hans", "en_FM", "sq_AL", "ko_KP", "en_150", "en_DE", "fr_MQ", "en_CA", "en_TR", "ro_MD", "es_VE", "fr_WF", "mt_MT", "kab", "nmg_CM", "ru_UA", "fr_MR", "tk_Latn_TM", "zh_Hans_MO", "mn_Cyrl_MN", "bs_Cyrl", "sw_UG", "ko_KR", "en_DG", "bo_IN", "en_CC", "shi_Tfng_MA", "lag", "it_SM", "en_TT", "ms_Arab_MY", "sq_MK", "ms_Latn", "bem_ZM", "kde", "ar_OM", "cgg", "bas", "kam", "zh_Hant", "es_MX", "en_GU", "fr_MU", "fr_KM", "ar_LB", "en_BA", "en_TV", "sr_Cyrl", "dje", "kab_DZ", "fil_PH", "vai", "hr_HR", "bs_Latn_BA", "nl_AW", "dav", "so_SO", "ar_PS", "en_FR", "uz_Cyrl", "ff_SN", "en_BB", "ki_KE", "naq", "en_SS", "mg_MG", "mas_KE", "en_RO", "en_PG", "mgh", "dyo_SN", "mas", "agq", "bn_BD", "haw", "nb_NO", "da_DK", "en_DK", "saq", "ug", "cy_GB", "fr_YT", "jmc", "ses_ML", "en_PH", "de_DE", "ar_YE", "bm_ML", "yo", "lkt_US", "uz_Arab_AF", "jgo", "uk", "sl_SI", "en_CH", "asa", "lg_UG", "mgo", "id_ID", "en_NA", "en_GY", "zgh", "pt_MZ", "fr_LU", "kk_Cyrl", "mas_TZ", "ur", "en_DM", "ta_MY", "en_BE", "mg", "fr_GA", "ka_GE", "nmg", "en_TZ", "eu_ES", "ar_DZ", "id", "so_DJ", "yav", "mk", "pa_Arab_PK", "ml", "en_ER", "ig", "mn", "ksb", "uz", "vi_VN", "ii", "en_PK", "ee", "mr", "ms", "en_ES", "sq_XK", "it_CH", "mt", "en_CK", "br_FR", "sr_Cyrl_XK", "ksf", "en_SX", "bg_BG", "en_PL", "af", "el", "cs_CZ", "fr_TD", "zh_Hans_HK", "is", "my", "en", "it", "ii_CN", "eo", "iu", "en_ZA", "en_AD", "ak", "en_RU", "kkj_CM", "am", "es", "et", "uk_UA"} set isoLang to (current application’s NSLocale’s ISOLanguageCodes()) as anything log isoLang –> {"aa", "ab", "ace", "ach", "ada", "ady", "ae", "af", "afa", "afh", "agq", "ain", "ak", "akk", "ale", "alg", "alt", "am", "an", "ang", "anp", "apa", "ar", "arc", "arn", "arp", "art", "arw", "as", "asa", "ast", "ath", "aus", "av", "awa", "ay", "az", "ba", "bad", "bai", "bal", "ban", "bas", "bat", "bax", "bbj", "be", "bej", "bem", "ber", "bez", "bfd", "bg", "bh", "bho", "bi", "bik", "bin", "bkm", "bla", "bm", "bn", "bnt", "bo", "br", "bra", "brx", "bs", "bss", "btk", "bua", "bug", "bum", "byn", "byv", "ca", "cad", "cai", "car", "cau", "cay", "cch", "ce", "ceb", "cel", "cgg", "ch", "chb", "chg", "chk", "chm", "chn", "cho", "chp", "chr", "chy", "ckb", "cmc", "co", "cop", "cpe", "cpf", "cpp", "cr", "crh", "crp", "cs", "csb", "cu", "cus", "cv", "cy", "da", "dak", "dar", "dav", "day", "de", "del", "den", "dgr", "din", "dje", "doi", "dra", "dsb", "dua", "dum", "dv", "dyo", "dyu", "dz", "dzg", "ebu", "ee", "efi", "egy", "eka", "el", "elx", "en", "enm", "eo", "es", "et", "eu", "ewo", "fa", "fan", "fat", "ff", "fi", "fil", "fiu", "fj", "fo", "fon", "fr", "frm", "fro", "frr", "frs", "fur", "fy", "ga", "gaa", "gay", "gba", "gd", "gem", "gez", "gil", "gl", "gmh", "gn", "goh", "gon", "gor", "got", "grb", "grc", "gsw", "gu", "guz", "gv", "gwi", "ha", "hai", "haw", "he", "hi", "hil", "him", "hit", "hmn", "ho", "hr", "hsb", "ht", "hu", "hup", "hy", "hz", "ia", "iba", "ibb", "id", "ie", "ig", "ii", "ijo", "ik", "ilo", "inc", "ine", "inh", "io", "ira", "iro", "is", "it", "iu", "ja", "jbo", "jgo", "jmc", "jpr", "jrb", "jv", "ka", "kaa", "kab", "kac", "kaj", "kam", "kar", "kaw", "kbd", "kbl", "kcg", "kde", "kea", "kfo", "kg", "kha", "khi", "kho", "khq", "ki", "kj", "kk", "kkj", "kl", "kln", "km", "kmb", "kn", "ko", "kok", "kos", "kpe", "kr", "krc", "krl", "kro", "kru", "ks", "ksb", "ksf", "ksh", "ku", "kum", "kut", "kv", "kw", "ky", "la", "lad", "lag", "lah", "lam", "lb", "lez", "lg", "li", "lkt", "ln", "lo", "lol", "loz", "lt", "lu", "lua", "lui", "lun", "luo", "lus", "luy", "lv", "mad", "maf", "mag", "mai", "mak", "man", "map", "mas", "mde", "mdf", "mdr", "men", "mer", "mfe", "mg", "mga", "mgh", "mgo", "mh", "mi", "mic", "min", "mis", "mk", "mkh", "ml", "mn", "mnc", "mni", "mno", "mo", "moh", "mos", "mr", "ms", "mt", "mua", "mul", "mun", "mus", "mwl", "mwr", "my", "mye", "myn", "myv", "na", "nah", "nai", "nap", "naq", "nb", "nd", "nds", "ne", "new", "ng", "nia", "nic", "niu", "nl", "nmg", "nn", "nnh", "no", "nog", "non", "nqo", "nr", "nso", "nub", "nus", "nv", "nwc", "ny", "nym", "nyn", "nyo", "nzi", "oc", "oj", "om", "or", "os", "osa", "ota", "oto", "pa", "paa", "pag", "pal", "pam", "pap", "pau", "peo", "phi", "phn", "pi", "pl", "pon", "pra", "pro", "ps", "pt", "qu", "raj", "rap", "rar", "rm", "rn", "ro", "roa", "rof", "rom", "ru", "rup", "rw", "rwk", "sa", "sad", "sah", "sai", "sal", "sam", "saq", "sas", "sat", "sba", "sbp", "sc", "scn", "sco", "sd", "se", "see", "seh", "sel", "sem", "ses", "sg", "sga", "sgn", "shi", "shn", "shu", "si", "sid", "sio", "sit", "sk", "sl", "sla", "sm", "sma", "smi", "smj", "smn", "sms", "sn", "snk", "so", "sog", "son", "sq", "sr", "srn", "srr", "ss", "ssa", "ssy", "st", "su", "suk", "sus", "sux", "sv", "sw", "swb", "swc", "syc", "syr", "ta", "tai", "te", "tem", "teo", "ter", "tet", "tg", "th", "ti", "tig", "tiv", "tk", "tkl", "tl", "tlh", "tli", "tmh", "tn", "to", "tog", "tpi", "tr", "trv", "ts", "tsi", "tt", "tum", "tup", "tut", "tvl", "tw", "twq", "ty", "tyv", "tzm", "udm", "ug", "uga", "uk", "umb", "und", "ur", "uz", "vai", "ve", "vi", "vo", "vot", "vun", "wa", "wae", "wak", "wal", "war", "was", "wen", "wo", "xal", "xh", "xog", "yao", "yap", "yav", "ybb", "yi", "yo", "ypk", "yue", "za", "zap", "zbl", "zen", "zgh", "zh", "znd", "zu", "zun", "zxx", "zza"} set commonCurrency to (current application’s NSLocale’s commonISOCurrencyCodes()) as anything log commonCurrency –> (NSArray) {"AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GWP", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LVL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO", "MUR", "MVR", "MWK", "MXN", "MYR", "MZE", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SKK", "SLL", "SOS", "SRD", "SSP", "STD", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VEF", "VND", "VUV", "WST", "XAF", "XCD", "XOF", "XPF", "YER", "ZAR", "ZMW"} set aLoc to (current application’s NSLocale’s localeIdentifierFromWindowsLocaleCode:1041) as anything log aLoc –> "ja_JP" — https://msdn.microsoft.com/ja-jp/library/Cc392381.aspx set aLocID to (current application’s NSLocale’s windowsLocaleCodeFromLocaleIdentifier:"ja_JP") as anything log aLocID –> 1041 set prefLang to (current application’s NSLocale’s preferredLanguages()) as anything log prefLang –> {"ja", "en-US", "en-GB", "fr", "en"} set aLangDIrect1 to (current application’s NSLocale’s characterDirectionForLanguage:"ja") as anything –日本語 log aLangDIrect1 –> 1 –NSLocaleLanguageDirectionLeftToRight set aLangDIrect2 to (current application’s NSLocale’s characterDirectionForLanguage:"ar") as anything –アラビア語 log aLangDIrect2 –> 2 –NSLocaleLanguageDirectionRightToLeft set aLangLineDIrect1 to (current application’s NSLocale’s lineDirectionForLanguage:"ja") as anything –日本語 log aLangLineDIrect1 –> 3 –NSLocaleLanguageDirectionTopToBottom set aLangLineDIrect2 to (current application’s NSLocale’s lineDirectionForLanguage:"ar") as anything –アラビア語 log aLangLineDIrect2 –> 3 –NSLocaleLanguageDirectionTopToBottom |
すべてのLocaleから各種情報を取得
AppleScript名:すべてのLocaleから各種情報を取得 |
— Created 2015-10-03 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set allLocaleIdentifiers to (current application’s NSLocale’s availableLocaleIdentifiers()) as list set cList to {} repeat with i in allLocaleIdentifiers set j to contents of i set tmpLoc to (current application’s NSLocale’s alloc()’s initWithLocaleIdentifier:j) set aLangCode to (tmpLoc’s objectForKey:(current application’s NSLocaleLanguageCode)) as text set aCountryCode to (tmpLoc’s objectForKey:(current application’s NSLocaleCountryCode)) as text set aCCYSymbol to (tmpLoc’s objectForKey:(current application’s NSLocaleCurrencySymbol)) as text set aLocID to (tmpLoc’s objectForKey:(current application’s NSLocaleIdentifier)) as text –set aCountryName to (tmpLoc’s displayNameForKey:(current application’s NSLocaleCountryCode)) set locIDDisplayName to (tmpLoc’s displayNameForKey:(current application’s NSLocaleIdentifier) value:aLocID) as text set the end of cList to {aLocID, aLangCode, aCountryCode, aCCYSymbol, locIDDisplayName} end repeat cList –> {{"eu", "eu", "missing value", "¤", "euskara"},…. {"ja_JP", "ja", "JP", "¥", "日本語 (日本)"}, ….. {"ja", "ja", "missing value", "¤", "日本語"}, ………., {"en_US", "en", "US", "$", "English (United States)"}, {"en_US_POSIX", "en", "US", "$", "English (United States, Computer)"}, {"zh-Hans", "zh", "missing value", "¤", "中文(简体)"},….. {"zh-Hant", "zh", "missing value", "¤", "中文(繁體)"}, ….{"zh-Hans_HK", "zh", "HK", "HK$", "中文(简体、中国香港特别行政区)"},} |
Current Localeから各種情報を取得する
AppleScript名:Current Localeから各種情報を取得する |
— Created 2016-10-12 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set curLocale to current application’s NSLocale’s currentLocale() set aDS1 to curLocale’s objectForKey:(current application’s NSLocaleDecimalSeparator) –> (NSString) "." set aDS2 to curLocale’s objectForKey:(current application’s NSLocaleGroupingSeparator) –> (NSString) "," set aDS3 to curLocale’s objectForKey:(current application’s NSLocaleCurrencySymbol) –> (NSString) "¥" set aDS4 to curLocale’s objectForKey:(current application’s NSLocaleCurrencyCode) –> (NSString) "JPY" set aDS5 to curLocale’s objectForKey:(current application’s NSLocaleCollatorIdentifier) –> (NSString) "ja-JP" set aDS6 to curLocale’s objectForKey:(current application’s NSLocaleQuotationBeginDelimiterKey) –> (NSString) "「" set aDS7 to curLocale’s objectForKey:(current application’s NSLocaleQuotationEndDelimiterKey) –> (NSString) "」" set aDS8 to curLocale’s objectForKey:(current application’s NSLocaleAlternateQuotationBeginDelimiterKey) –> (NSString) "『" set aDS9 to curLocale’s objectForKey:(current application’s NSLocaleAlternateQuotationEndDelimiterKey) –> (NSString) "』" set aDS10 to curLocale’s objectForKey:(current application’s NSLocaleIdentifier) –> (NSString) "ja_JP" set aDS11 to curLocale’s objectForKey:(current application’s NSLocaleLanguageCode) –> (NSString) "ja" set aDS12 to curLocale’s objectForKey:(current application’s NSLocaleCountryCode) –> (NSString) "JP" set aDS13 to curLocale’s objectForKey:(current application’s NSLocaleScriptCode) –> missing value set aDS14 to curLocale’s objectForKey:(current application’s NSLocaleVariantCode) –> missing value set aDS15 to curLocale’s objectForKey:(current application’s NSLocaleExemplarCharacterSet) –> (__NSCFCharacterSet) <__NSCFCharacterSet: 0x60800124d890> set aDS16 to curLocale’s objectForKey:(current application’s NSLocaleCalendar) –> (_NSCopyOnWriteCalendarWrapper) <_NSCopyOnWriteCalendarWrapper: 0x610000232ca0> set aDS17 to curLocale’s objectForKey:(current application’s NSLocaleCollationIdentifier) –> missing value set aDS18 to curLocale’s objectForKey:(current application’s NSLocaleUsesMetricSystem) –> (NSNumber) 1 set aDS19 to curLocale’s objectForKey:(current application’s NSLocaleMeasurementSystem) –> (NSString) "Metric" |
Locale情報を取得する
AppleScript名:Locale情報を取得する |
— Created 2015-09-11 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aLocale to (current application’s NSLocale’s currentLocale’s objectForKey:(current application’s NSLocaleIdentifier)) as list of string or string –as anything –> "ja_JP" set aLangList to (current application’s NSLocale’s preferredLanguages()) as list of string or string –as anything –> {"ja", "en-US", "en-GB", "fr", "en"} set aLocList to (current application’s NSLocale’s availableLocaleIdentifiers()) as list of string or string –as anything –> {"eu", "hr_BA", "en_CM", "rw_RW", "en_SZ", "tk_Latn", "uz_Arab", "he_IL", "ar", "en_PN", "as", "en_NF", "rwk_TZ", "zh_Hant_TW", "gsw_LI", "th_TH", "ta_IN", "es_EA", "fr_GF", "ar_001", "en_RW", "tr_TR", "de_CH", "ee_TG", "en_NG", "fr_TG", "az", "fr_SC", "es_HN", "en_AG", "ru_KZ", "gsw", "dyo", "so_ET", "zh_Hant_MO", "de_BE", "km_KH", "my_MM", "mgh_MZ", "ee_GH", "es_EC", "kw_GB", "rm_CH", "en_ME", "nyn", "mk_MK", "bs_Cyrl_BA", "ar_MR", "en_BM", "ms_Arab", "en_AI", "gl_ES", "en_PR", "ha_Latn_GH", "ne_IN", "or_IN", "khq_ML", "en_MG", "pt_TL", "en_LC", "ta_SG", "jmc_TZ", "om_ET", "lv_LV", "es_US", "en_PT", "vai_Latn_LR", "to_TO", "en_NL", "cgg_UG", "ta", "en_MH", "iu_Cans_CA", "zu_ZA", "shi_Latn_MA", "brx_IN", "ar_KM", "en_AL", "te", "chr_US", "yo_BJ", "fr_VU", "pa", "tg", "ks_Arab", "kea", "te_IN", "th", "fr_RE", "ur_IN", "yo_NG", "ti", "guz_KE", "tk", "kl_GL", "ksf_CM", "mua_CM", "lag_TZ", "fr_TN", "es_PA", "pl_PL", "to", "hi_IN", "dje_NE", "es_GQ", "kok_IN", "pl", "tr", "bem", "ha", "ckb", "lg", "fr_GN", "en_PW", "en_NO", "nyn_UG", "sr_Latn_RS", "pa_Guru", "he", "swc_CD", "ug_Arab", "lu_CD", "mgo_CM", "sn_ZW", "en_BS", "ps_AF", "da", "ms_Latn_SG", "ps", "ln", "pt", "iu_Cans", "hi", "lo", "ebu", "de", "gu_IN", "seh", "en_CX", "en_ZM", "tzm_Latn_MA", "fr_HT", "fr_GP", "lt", "lu", "ln_CD", "vai_Latn", "el_GR", "lv", "en_KE", "sbp", "hr", "en_CY", "es_GT", "twq_NE", "zh_Hant_HK", "kln_KE", "fr_GQ", "chr", "hu", "es_UY", "fr_CA", "en_NR", "mer", "shi", "es_PE", "fr_SN", "bez", "sw_TZ", "kkj", "hy", "kk_Cyrl_KZ", "en_CZ", "teo_KE", "teo", "dz_BT", "ar_JO", "mer_KE", "khq", "ln_CF", "nn_NO", "en_MO", "ar_TD", "dz", "ses", "en_BW", "en_AS", "ar_IL", "ms_Latn_BN", "bo_CN", "nnh", "teo_UG", "hy_AM", "ln_CG", "sr_Latn_BA", "en_MP", "ksb_TZ", "ar_SA", "ar_LY", "en_AT", "so_KE", "fr_CD", "af_NA", "en_NU", "es_PH", "en_KI", "en_JE", "lkt", "en_AU", "fa_IR", "uz_Latn_UZ", "ky_Cyrl", "zh_Hans_CN", "ewo_CM", "fr_PF", "ca_IT", "en_BZ", "ar_KW", "pt_GW", "fr_FR", "am_ET", "en_VC", "fr_DJ", "fr_CF", "es_SV", "en_MS", "pt_ST", "ar_SD", "luy_KE", "swc", "de_LI", "fr_CG", "zh_Hans_SG", "en_MT", "ewo", "af_ZA", "om_KE", "nl_SR", "es_ES", "es_DO", "ar_IQ", "fr_CH", "nnh_CM", "es_419", "en_MU", "en_US_POSIX", "yav_CM", "luo_KE", "dua_CM", "et_EE", "en_IE", "ak_GH", "rwk", "es_CL", "kea_CV", "fr_CI", "fr_BE", "en_NZ", "ky_Cyrl_KG", "en_LR", "en_KN", "nb_SJ", "sg", "sr_Cyrl_RS", "ru_RU", "en_ZW", "sv_AX", "si", "ga_IE", "en_VG", "sk", "agq_CM", "fr_BF", "naq_NA", "sl", "en_MW", "mr_IN", "az_Latn", "en_LS", "de_AT", "ka", "sn", "sr_Latn_ME", "fr_NC", "so", "is_IS", "twq", "ig_NG", "sq", "fo_FO", "sr", "tzm", "ga", "om", "en_LT", "bas_CM", "ki", "nl_BE", "ar_QA", "sv", "kk", "sw", "es_CO", "az_Latn_AZ", "rn_BI", "or", "kl", "ca", "en_VI", "km", "kn", "en_LU", "fr_SY", "ar_TN", "en_JM", "fr_PM", "ko", "fr_NE", "fr_MA", "gl", "ru_MD", "saq_KE", "ks", "fr_CM", "gv_IM", "fr_BI", "en_LV", "ks_Arab_IN", "es_NI", "en_GB", "kw", "nl_SX", "dav_KE", "tr_CY", "ky", "en_UG", "tzm_Latn", "en_TC", "nus_SD", "ar_EG", "fr_BJ", "gu", "es_PR", "fr_RW", "sr_Cyrl_BA", "gv", "fr_MC", "cs", "bez_TZ", "es_CR", "asa_TZ", "ar_EH", "ms_Arab_BN", "mn_Cyrl", "sbp_TZ", "ha_Latn_NE", "lt_LT", "mfe", "en_GD", "cy", "ca_FR", "es_BO", "fr_BL", "bn_IN", "uz_Cyrl_UZ", "az_Cyrl", "en_IM", "sw_KE", "en_SB", "ur_PK", "pa_Arab", "haw_US", "ar_SO", "en_IN", "ha_Latn", "fil", "fr_MF", "en_WS", "es_CU", "ja_JP", "en_SC", "en_IO", "pt_PT", "en_HK", "en_GG", "fr_MG", "de_LU", "ms_Latn_MY", "tg_Cyrl", "en_SD", "shi_Tfng", "ln_AO", "ug_Arab_CN", "as_IN", "en_GH", "ro_RO", "jgo_CM", "dua", "en_UM", "en_SE", "kn_IN", "en_KY", "vun_TZ", "kln", "en_GI", "ca_ES", "rof", "pt_CV", "kok", "pt_BR", "ar_DJ", "zh", "fi_FI", "tg_Cyrl_TJ", "es_PY", "ar_SS", "mua", "sr_Cyrl_ME", "vai_Vaii_LR", "en_001", "xog_UG", "en_TK", "si_LK", "en_SG", "nl_NL", "vi", "sv_SE", "pt_AO", "fr_DZ", "ca_AD", "xog", "en_IS", "nb", "seh_MZ", "es_AR", "sk_SK", "en_SH", "ti_ER", "nd", "az_Cyrl_AZ", "zu", "ne", "nd_ZW", "el_CY", "en_IT", "nl_BQ", "da_GL", "ja", "rm", "fr_ML", "rn", "en_VU", "rof_TZ", "ro", "ebu_KE", "ru_KG", "en_SI", "sg_CF", "mfe_MU", "nl", "brx", "bs_Latn", "fa", "zgh_MA", "en_GM", "shi_Latn", "en_FI", "nn", "en_EE", "ru", "kam_KE", "vai_Vaii", "ar_ER", "ti_ET", "rw", "ff", "luo", "fa_AF", "ha_Latn_NG", "nl_CW", "en_HR", "en_FJ", "fi", "pt_MO", "be", "en_US", "en_TO", "en_SK", "bg", "ru_BY", "it_IT", "ml_IN", "gsw_CH", "fo", "sv_FI", "en_FK", "nus", "ta_LK", "vun", "sr_Latn", "fr", "en_SL", "bm", "ar_BH", "guz", "bn", "bo", "ar_SY", "lo_LA", "ne_NP", "uz_Latn", "be_BY", "es_IC", "sr_Latn_XK", "ar_MA", "pa_Guru_IN", "br", "luy", "kde_TZ", "bs", "hu_HU", "ar_AE", "en_HU", "zh_Hans", "en_FM", "sq_AL", "ko_KP", "en_150", "en_DE", "fr_MQ", "en_CA", "en_TR", "ro_MD", "es_VE", "fr_WF", "mt_MT", "kab", "nmg_CM", "ru_UA", "fr_MR", "tk_Latn_TM", "zh_Hans_MO", "mn_Cyrl_MN", "bs_Cyrl", "sw_UG", "ko_KR", "en_DG", "bo_IN", "en_CC", "shi_Tfng_MA", "lag", "it_SM", "en_TT", "ms_Arab_MY", "sq_MK", "ms_Latn", "bem_ZM", "kde", "ar_OM", "cgg", "bas", "kam", "zh_Hant", "es_MX", "en_GU", "fr_MU", "fr_KM", "ar_LB", "en_BA", "en_TV", "sr_Cyrl", "dje", "kab_DZ", "fil_PH", "vai", "hr_HR", "bs_Latn_BA", "nl_AW", "dav", "so_SO", "ar_PS", "en_FR", "uz_Cyrl", "ff_SN", "en_BB", "ki_KE", "naq", "en_SS", "mg_MG", "mas_KE", "en_RO", "en_PG", "mgh", "dyo_SN", "mas", "agq", "bn_BD", "haw", "nb_NO", "da_DK", "en_DK", "saq", "ug", "cy_GB", "fr_YT", "jmc", "ses_ML", "en_PH", "de_DE", "ar_YE", "bm_ML", "yo", "lkt_US", "uz_Arab_AF", "jgo", "uk", "sl_SI", "en_CH", "asa", "lg_UG", "mgo", "id_ID", "en_NA", "en_GY", "zgh", "pt_MZ", "fr_LU", "kk_Cyrl", "mas_TZ", "ur", "en_DM", "ta_MY", "en_BE", "mg", "fr_GA", "ka_GE", "nmg", "en_TZ", "eu_ES", "ar_DZ", "id", "so_DJ", "yav", "mk", "pa_Arab_PK", "ml", "en_ER", "ig", "mn", "ksb", "uz", "vi_VN", "ii", "en_PK", "ee", "mr", "ms", "en_ES", "sq_XK", "it_CH", "mt", "en_CK", "br_FR", "sr_Cyrl_XK", "ksf", "en_SX", "bg_BG", "en_PL", "af", "el", "cs_CZ", "fr_TD", "zh_Hans_HK", "is", "my", "en", "it", "ii_CN", "eo", "iu", "en_ZA", "en_AD", "ak", "en_RU", "kkj_CM", "am", "es", "et", "uk_UA"} |
指定言語環境(Locale)の月名、曜日名を取得する
AppleScript名:指定言語環境(Locale)の月名、曜日名を取得する |
use AppleScript version "2.4" use scripting additions use framework "Foundation" set aList to getLocalizedDaynames("en_US") –> {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"} set aList to getLocalizedDaynames("fr_FR") –> {"Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"} set aList to getLocalizedDaynames("ja_JP") –> {"日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日"} set aList to getLocalizedDaynames("zh-Hans") –> {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"} set bList to getLocalizedMonthnames("en_US") –> {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"} set bList to getLocalizedMonthnames("fr_FR") –> {"janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"} set bList to getLocalizedMonthnames("ja_JP") –> {"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"} set bList to getLocalizedMonthnames("zh-Hans") –> {"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"} –ローカライズされた曜日名称を返す on getLocalizedDaynames(aLoc) set df to current application’s NSDateFormatter’s alloc()’s init() df’s setLocale:(current application’s NSLocale’s localeWithLocaleIdentifier:aLoc) set dayNames to df’s standaloneWeekdaySymbols() as list return dayNames end getLocalizedDaynames –ローカライズされた月名称を返す on getLocalizedMonthnames(aLoc) set df to current application’s NSDateFormatter’s alloc()’s init() df’s setLocale:(current application’s NSLocale’s localeWithLocaleIdentifier:aLoc) set monthNames to df’s standaloneMonthSymbols() as list return monthNames end getLocalizedMonthnames |
秒以下の時間待ちを計測
AppleScript名:秒以下の時間待ちを計測 |
— Created 2015-09-05 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set a1Dat to current application’s NSDate’s timeIntervalSinceReferenceDate() current application’s NSThread’s sleepForTimeInterval:("0.001" as real) –delay 0.001 set b1Dat to current application’s NSDate’s timeIntervalSinceReferenceDate() set c1Dat to b1Dat – a1Dat –> 0.001403987408 –> 0.001309990883 –> 0.001239955425 |
NSRangeの拡張、隣接検出
NSRangeの隣接検出を行うAppleScriptです。
NSRangeやNSRectの重なり検出機能はとても強力で、OLD Style AppleScriptの時代では考えられなかったほどの処理の柔軟性を得られています。
強力ではあるものの、機能が素朴であることもまた事実であります。AとBの2つのNSRangeが重なっていることしか検出できないのはつくづく残念です。
不満な点の筆頭に挙げられるのが、「隣接検出」機能がないことです。
たとえば、NSAttributedStringに対して書式を取得する処理を行うと、3点リーダー文字(「…」)や感嘆符(「!」)の箇所で、書式情報が変わっていないのに分割して取得されてしまいます。バグではないものの、あまり好ましくない挙動です。
こうした箇所は、Rangeとしては「隣接」しているわけで、同一書式のデータが「隣接」している場合には、続きのデータとしてまとめられた方がいいに決まっています。
そこで冒頭のNSRangeの隣接検出という話になるわけですが……NSRangeが1次元座標上の始点と終点の2つの情報で構成されているために、これらの情報を「拡張」します。
set aRange to current application’s NSMakeRange(10, 80)
というNSRangeを作ると、
–> {location:10, |length|:80}
始点(10)と、始点からの長さが80で、終点が90になります。
これを「拡張」すると、
–> {location:9, |length|:82}
となります。NSRangeが「隣接」は検出できなくても、重なり合いは検出できるため、「拡張」すれば、隣接時には「重なっている」と判定できることになります。
あとは、リストに入れたNSRangeのうち重なり合っているものをループで検出するルーチンを書けば、大量のNSRange同士の隣接を処理できることでしょう。
AppleScript名:NSRangeの拡張、隣接検出 |
— Created 2018-1-12 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aRange to current application’s NSMakeRange(10, 80) –original range –> {location:10, |length|:80} set bRange to extendRange(aRange) of me –Extended range –> {location:9, |length|:81} set cRange to current application’s NSMakeRange(90, 30) –compare target range –> {location:90, |length|:30} set aRes to current application’s NSIntersectionRange(aRange, cRange) –> {location:0, |length|:0}–Not adjacent set bRes to current application’s NSIntersectionRange(bRange, cRange) –> {location:90, |length|:1}–Adjacent –NSRangeの開始点とサイズを拡張 on extendRange(aRange) set aLoc to location of aRange set aLen to |length| of aRange if aLoc > 0 then set aLoc to aLoc – 1 end if set aLen to aLen + 2 set bRange to current application’s NSMakeRange(aLoc, aLen) return bRange end extendRange |
MaxRangeを取得する
AppleScript名:MaxRangeを取得する |
use AppleScript version "2.4" use scripting additions use framework "Foundation" set aRange to current application’s NSMakeRange(10, 80) –original range set aMaxX to current application’s NSMaxRange(aRange) –> 90 –set aMinX to current application’s NSMinRange(aRange)–最小はない |
NSRangeの基礎的な処理
AppleScript名:NSRangeの基礎的な処理 |
— Created 2017-12-12 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aRange to current application’s NSMakeRange(0, 100) –> {location:0, length:100} set maxRange to current application’s NSMaxRange(aRange) –最大値 –> 100 set rangeStr to (current application’s NSStringFromRange(aRange)) as string –> "{0, 100}" set bRange to current application’s NSRangeFromString(rangeStr) –> {location:0, length:100} set cRange to current application’s NSMakeRange(50, 80) set cRes to current application’s NSEqualRanges(aRange, cRange) –> false set dRes to current application’s NSEqualRanges(aRange, bRange) –> true set eRes to current application’s NSIntersectionRange(aRange, cRange) –> {location:50, length:50} set fRes to current application’s NSLocationInRange(50, aRange) –> true set gRes to current application’s NSLocationInRange(120, aRange) –> false set hRes to current application’s NSUnionRange(aRange, cRange) –> {location:0, length:130} |
数値に対して、小数点以下の数値の切り上げ、切り下げ
AppleScript名:数値に対して、小数点以下の数値の切り上げ、切り下げ |
— Created 2017-08-12 by Takaaki Naganoya — Modified 2017-08-28 by Shane Stanley use AppleScript version "2.4" use scripting additions use framework "Foundation" property NSString : a reference to current application’s NSString property NSNumber : a reference to current application’s NSNumber property NSNumberFormatter : a reference to current application’s NSNumberFormatter property NSNumberFormatterRoundUp : a reference to current application’s NSNumberFormatterRoundUp property NSNumberFormatterRoundDown : a reference to current application’s NSNumberFormatterRoundDown set a to 0.909661 set a1Res to roundingDownNumStr(a, 2) of me –> 0.9 on roundingDownNumStr(aNum as string, aDigit as integer) set a to NSString’s stringWithString:aNum set aa to a’s doubleValue() set aFormatter to NSNumberFormatter’s alloc()’s init() aFormatter’s setMaximumFractionDigits:aDigit aFormatter’s setRoundingMode:(NSNumberFormatterRoundDown) set aStr to aFormatter’s stringFromNumber:aa return (aStr as text) as real end roundingDownNumStr on roundingUpNumStr(aNum as string, aDigit as integer) set a to NSString’s stringWithString:aNum set aa to a’s doubleValue() set aFormatter to NSNumberFormatter’s alloc()’s init() aFormatter’s setMaximumFractionDigits:aDigit aFormatter’s setRoundingMode:(NSNumberFormatterRoundUp) set aStr to aFormatter’s stringFromNumber:aa return (aStr as text) as real end roundingUpNumStr |
数値文字列に対して、少数点以下の数値の切り上げ、切り下げ v2
AppleScript名:数値文字列に対して、少数点以下の数値の切り上げ、切り下げ v2 |
— Created 2017-08-12 by Takaaki Naganoya — Modified 2017-08-28 by Shane Stanley use AppleScript version "2.4" use scripting additions use framework "Foundation" property NSString : a reference to current application’s NSString property NSNumber : a reference to current application’s NSNumber property NSNumberFormatter : a reference to current application’s NSNumberFormatter property NSNumberFormatterRoundUp : a reference to current application’s NSNumberFormatterRoundUp property NSNumberFormatterRoundDown : a reference to current application’s NSNumberFormatterRoundDown set a to "0.9096617698669434" set a1Res to roundingDownNumStr(a, 2) of me set b to "0.0001830748806241899" set b1Res to roundingDownNumStr(b, 2) of me return {a1Res, b1Res} –> {0.9, 0.0} on roundingDownNumStr(aNum as string, aDigit as integer) set a to NSString’s stringWithString:aNum set aa to a’s doubleValue() set aFormatter to NSNumberFormatter’s alloc()’s init() aFormatter’s setMaximumFractionDigits:aDigit aFormatter’s setRoundingMode:(NSNumberFormatterRoundDown) set aStr to aFormatter’s stringFromNumber:aa return (aStr as text) as real end roundingDownNumStr on roundingUpNumStr(aNum as string, aDigit as integer) set a to NSString’s stringWithString:aNum set aa to a’s doubleValue() set aFormatter to NSNumberFormatter’s alloc()’s init() aFormatter’s setMaximumFractionDigits:aDigit aFormatter’s setRoundingMode:(NSNumberFormatterRoundUp) set aStr to aFormatter’s stringFromNumber:aa return (aStr as text) as real end roundingUpNumStr |