AppleScript名:NSByteCountFormatterCountStyleで数値から容量を表すテキストに変換 |
— Created 2014-12-03 by Takaaki Naganoya — 2014 Piyomaru Software use AppleScript version "2.5" use scripting additions use framework "Foundation" –NSByteCountFormatterCountStyle property NSByteCountFormatterCountStyleFile : 0 property NSByteCountFormatterCountStyleMemory : 1 property NSByteCountFormatterCountStyleDecimal : 2 property NSByteCountFormatterCountStyleBinary : 3 set a to 100000 –ファイル容量 set b to current application’s NSByteCountFormatter’s stringFromByteCount:a countStyle:(current application’s NSByteCountFormatterCountStyleFile) set c to b as string log result –> "100 KB" –メモリー容量 set d to current application’s NSByteCountFormatter’s stringFromByteCount:a countStyle:(current application’s NSByteCountFormatterCountStyleMemory) set e to b as string log result –> "100 KB" –10進数 set f to current application’s NSByteCountFormatter’s stringFromByteCount:a countStyle:(current application’s NSByteCountFormatterCountStyleDecimal) set g to b as string log result –> "100 KB" –バイナリ? set h to current application’s NSByteCountFormatter’s stringFromByteCount:a countStyle:(current application’s NSByteCountFormatterCountStyleBinary) set i to b as string log result –> "100 KB" |
カテゴリー: Text
NSNumberFormatterのテスト v2
AppleScript名:NSNumberFormatterのテスト v2 |
— Created 2014-12-03 by Takaaki Naganoya — 2014 Piyomaru Software use AppleScript version "2.5" use scripting additions use framework "Foundation" set a to 100000 set b to current application’s NSNumberFormatter’s localizedStringFromNumber:a numberStyle:(current application’s NSNumberFormatterNoStyle) set c to b as string –> "100000" set b to current application’s NSNumberFormatter’s localizedStringFromNumber:a numberStyle:(current application’s NSNumberFormatterDecimalStyle) set c to b as string –> "100,000" set b to current application’s NSNumberFormatter’s localizedStringFromNumber:a numberStyle:(current application’s NSNumberFormatterCurrencyStyle) set c to b as string –> "¥100,000" set aa to 0.1 set b to current application’s NSNumberFormatter’s localizedStringFromNumber:aa numberStyle:(current application’s NSNumberFormatterPercentStyle) set c to b as string –> "10%" set b to current application’s NSNumberFormatter’s localizedStringFromNumber:a numberStyle:(current application’s NSNumberFormatterScientificStyle) set c to b as string –> "1E5" set b to current application’s NSNumberFormatter’s localizedStringFromNumber:a numberStyle:(current application’s NSNumberFormatterSpellOutStyle) set c to b as string –> "十万" set a to 111111111 set b to current application’s NSNumberFormatter’s localizedStringFromNumber:a numberStyle:(current application’s NSNumberFormatterSpellOutStyle) set c to b as string –> "一億千百十一万千百十一" set a to 9.11111111111E+16 set b to current application’s NSNumberFormatter’s localizedStringFromNumber:a numberStyle:(current application’s NSNumberFormatterSpellOutStyle) set c to b as string –> "一京八千十四兆三千九百八十五億九百四十八万千九百八十四" |
DDUnitConverterで時速を秒速に変換
–> ddUnitConversionKit.framework
AppleScript名:DDUnitConverterで時速を秒速に変換 |
— Created 2015-11-19 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "ddUnitConversionKit" –https://github.com/davedelong/DDUnitConverter –enums in DDVelocityUnitConverter.h property DDVelocityUnitCentimetersPerHour : 0 property DDVelocityUnitCentimetersPerMinute : 1 property DDVelocityUnitCentimetersPerSecond : 2 property DDVelocityUnitFeetPerHour : 3 property DDVelocityUnitFeetPerMinute : 4 property DDVelocityUnitFeetPerSecond : 5 property DDVelocityUnitInchesPerHour : 6 property DDVelocityUnitInchesPerMinute : 7 property DDVelocityUnitInchesPerSecond : 8 property DDVelocityUnitKilometersPerHour : 9 property DDVelocityUnitKilometersPerMinute : 10 property DDVelocityUnitKilometersPerSecond : 11 property DDVelocityUnitKnots : 12 property DDVelocityUnitLight : 13 property DDVelocityUnitMach : 14 property DDVelocityUnitMetersPerHour : 15 property DDVelocityUnitMetersPerMinute : 16 property DDVelocityUnitMetersPerSecond : 17 property DDVelocityUnitMilesPerHour : 18 property DDVelocityUnitMilesPerMinute : 19 property DDVelocityUnitMilesPerSecond : 20 property DDVelocityUnitFurlongsPerFortnight : 21 –時速100kmを秒速kmに変換 set aVal to ((current application’s DDUnitConverter’s velocityUnitConverter())’s convertNumber:100 fromUnit:(DDVelocityUnitKilometersPerHour) toUnit:(DDVelocityUnitKilometersPerSecond)) as real –> 0.027777777778 |
ポイント数値のテキストをmmに書き換える v4
AppleScript名:ポイント数値のテキストをmmに書き換える v4 |
set aRes to " 772.4 x 1082.8 pts" set sizeRes to changePTStoMM(aRes) of me log result –> {strDat:"272.6572 x 382.2284 mm", numDat:{272.6572, 382.2284}} set aRes to "595 x 842 pts (A4)" set sizeRes to changePTStoMM(aRes) of me log result –> {strDat:"210.035 x 297.226 mm", numDat:{210.035, 297.226}} set aRes to " 2242.2 x 1618.58 pts" set sizeRes to changePTStoMM(aRes) of me log result –> {strDat:"210.035 x 297.226 mm", numDat:{210.035, 297.226}} –ポイント数値のテキストをmmに書き換える v4 –問題が見つかったので書き換え(2010/3/12) –超泥縄式の対応だったので、「(A4)」の判型表示が行われないケースにはきちんと対応できていなかった –慌てて直した。ちゃんと文字と数字のアトリビュートを取得しているのでまじめに活用してみた on changePTStoMM(aText) set wList to words of aText set attrList to {} repeat with i in wList set the end of attrList to numChk(i) of me end repeat set aCount to length of wList set aReNumList to {} repeat with i from 1 to (aCount) set anItem to item i of wList set anAttr to item i of attrList if anAttr = true then set the end of aReNumList to (point2mm(anItem as number) of me) end if end repeat –エラー時の対応(多分ないと思うが、一応) if length of aReNumList is not equal to 2 then return false –まじめに数値データから文字列を組み立てて返す set num1 to contents of item 1 of aReNumList set num2 to contents of item 2 of aReNumList set aText to ((num1 as string) & " x " & num2 as string) & " mm" return {strDat:aText, numDat:aReNumList} end changePTStoMM –リストを任意のデリミタ付きでテキストに on makeStrFromListWithDelim(aDelim, aList) set aText to "" set curDelim to AppleScript’s text item delimiters set AppleScript’s text item delimiters to aDelim set aText to aList as text set AppleScript’s text item delimiters to curDelim return aText end makeStrFromListWithDelim –ポイントからmmへの変換 on point2mm(a) return (a * 0.353) –1ポイント=0.353mm end point2mm –数値かどうか調べる on numChk(aNum) set aClass to (class of aNum) as string if aClass = "number" or aClass = "double" or aClass = "integer" or aClass = "real" then return true else if aClass = "string" or aClass = "text" or aClass = "unicode text" then try set bNum to aNum as number return true on error return false end try end if end numChk on trimStrFromTo(aStr, fromStr, toStr) –fromStrは前から探す if fromStr is not equal to "" then set sPos to (offset of fromStr in aStr) + 1 else set sPos to 1 end if –toStrは後ろから探す if toStr is not equal to "" then set b to (reverse of characters of aStr) as string set ePos to (offset of toStr in b) set ePos to ((length of aStr) – ePos) else set ePos to length of aStr end if set aRes to text sPos thru ePos of aStr return aRes end trimStrFromTo |
ローカライズドな期間表記
AppleScript名:ローカライズドな期間表記 |
— Created 2016-01-14 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" –Date Interval set engNSDateIntervalFormatter to current application’s NSDateIntervalFormatter’s alloc()’s init() engNSDateIntervalFormatter’s setLocale:(current application’s NSLocale’s localeWithLocaleIdentifier:"en-US") engNSDateIntervalFormatter’s setDateStyle:(current application’s NSDateIntervalFormatterLongStyle) engNSDateIntervalFormatter’s setDateTemplate:(current application’s NSDateFormatter’s alloc()’s init()’s setDateFormat:"yyyy-MM-dd HH:mm") engNSDateIntervalFormatter’s setTimeStyle:(current application’s NSDateIntervalFormatterNoStyle) engNSDateIntervalFormatter’s setTimeZone:(current application’s NSTimeZone’s timeZoneWithAbbreviation:"JST") engNSDateIntervalFormatter’s setCalendar:(current application’s NSCalendar’s currentCalendar()) set startDate to current application’s NSDate’s |date|() set endDate to current application’s NSDate’s dateWithTimeInterval:86400 sinceDate:startDate set outEString to (engNSDateIntervalFormatter’s stringFromDate:startDate toDate:endDate) as string –> "1/14/16 – 1/15/16"–ShortStyle –> "Jan 14 – 15, 2016"–Medium Style –> "January 14 – 15, 2016"–Long Style –> "Thursday, January 14 – Friday, January 15, 2016"–Full Style set jpnNSDateIntervalFormatter to current application’s NSDateIntervalFormatter’s alloc()’s init() jpnNSDateIntervalFormatter’s setLocale:(current application’s NSLocale’s localeWithLocaleIdentifier:"ja") jpnNSDateIntervalFormatter’s setDateStyle:(current application’s NSDateIntervalFormatterFullStyle) jpnNSDateIntervalFormatter’s setDateTemplate:(current application’s NSDateFormatter’s alloc()’s init()’s setDateFormat:"yyyy-MM-dd HH:mm") jpnNSDateIntervalFormatter’s setTimeStyle:(current application’s NSDateIntervalFormatterNoStyle) jpnNSDateIntervalFormatter’s setTimeZone:(current application’s NSTimeZone’s timeZoneWithAbbreviation:"JST") jpnNSDateIntervalFormatter’s setCalendar:(current application’s NSCalendar’s currentCalendar()) set startDate to current application’s NSDate’s |date|() set endDate to current application’s NSDate’s dateWithTimeInterval:86400 sinceDate:startDate set outJString to (jpnNSDateIntervalFormatter’s stringFromDate:startDate toDate:endDate) as string –> "2016/01/14~2016/01/15"–ShortStyle –> "2016/01/14~2016/01/15"–Medium Style –> "2016/01/14~2016/01/15"–Long Style –> "2016/01/14(木曜日)~2016/01/15(金曜日)"–Full Style |
ローカライズドな度量衡表示(エネルギー)
AppleScript名:ローカライズドな度量衡表示(エネルギー) |
— Created 2015-11-20 by Shane Stanley — Modified 2016-01-14 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" –Energy set engEFormatter to current application’s NSEnergyFormatter’s alloc()’s init() engEFormatter’s numberFormatter()’s setLocale:(current application’s NSLocale’s localeWithLocaleIdentifier:"en-US") engEFormatter’s setUnitStyle:(current application’s NSFormattingUnitStyleLong) engEFormatter’s setForFoodEnergyUse:true set a1Res to (engEFormatter’s stringFromJoules:85) as string –> "20.315 calories" engEFormatter’s setForFoodEnergyUse:false set a1Res to (engEFormatter’s stringFromJoules:85) as string –> "20.315 calories" set a2Res to (engEFormatter’s stringFromValue:1 unit:(current application’s NSEnergyFormatterUnitJoule)) as string –joule –> "1 joule" set a3Res to (engEFormatter’s stringFromValue:1 unit:(current application’s NSEnergyFormatterUnitKilojoule)) as string –k joule –> "1 kilojoule" set a4Res to (engEFormatter’s stringFromValue:1 unit:(current application’s NSEnergyFormatterUnitCalorie)) as string –Cal –> "1 calorie" set a5Res to (engEFormatter’s stringFromValue:1 unit:(current application’s NSEnergyFormatterUnitKilocalorie)) as string –K Cal –> "1 kilocalorie" set jpnEFormatter to current application’s NSEnergyFormatter’s alloc()’s init() jpnEFormatter’s numberFormatter()’s setLocale:(current application’s NSLocale’s localeWithLocaleIdentifier:"ja") jpnEFormatter’s setUnitStyle:(current application’s NSFormattingUnitStyleLong) jpnEFormatter’s setForFoodEnergyUse:true set j1Res to (jpnEFormatter’s stringFromJoules:85) as string –> "85ジュール" jpnEFormatter’s setForFoodEnergyUse:false set j1Res to (jpnEFormatter’s stringFromJoules:85) as string –> "85ジュール" set j2Res to (jpnEFormatter’s stringFromValue:1 unit:(current application’s NSEnergyFormatterUnitJoule)) as string –joule –> "1ジュール" set j3Res to (jpnEFormatter’s stringFromValue:1 unit:(current application’s NSEnergyFormatterUnitKilojoule)) as string –k joule –> "1キロジュール" set j4Res to (jpnEFormatter’s stringFromValue:1 unit:(current application’s NSEnergyFormatterUnitCalorie)) as string –Cal –> "1熱力学カロリー" set j5Res to (jpnEFormatter’s stringFromValue:1 unit:(current application’s NSEnergyFormatterUnitKilocalorie)) as string –K Cal –> "1キロカロリー" |
ローカライズドな度量衡表示(重さ)
AppleScript名:ローカライズドな度量衡表示(重さ) |
— Created 2015-11-20 by Shane Stanley — Modified 2016-01-14 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" –Weight set engMFormatter to current application’s NSMassFormatter’s alloc()’s init() engMFormatter’s numberFormatter()’s setLocale:(current application’s NSLocale’s localeWithLocaleIdentifier:"en-US") engMFormatter’s setUnitStyle:(current application’s NSFormattingUnitStyleLong) –NSFormattingUnitStyleShort, NSFormattingUnitStyleMedium, NSFormattingUnitStyleLong set a1Res to (engMFormatter’s stringFromKilograms:85) as string –Kg –> "187.393 pounds" set a2Res to (engMFormatter’s stringFromValue:1 unit:(current application’s NSMassFormatterUnitGram)) as string –g –> "1 gram" set a3Res to (engMFormatter’s stringFromValue:1 unit:(current application’s NSMassFormatterUnitOunce)) as string –オンス –> "1 ounce" set a4Res to (engMFormatter’s stringFromValue:1 unit:(current application’s NSMassFormatterUnitStone)) as string –ストーン(=14 pounds) –> "1 stone" set jpnMFormatter to current application’s NSMassFormatter’s alloc()’s init() jpnMFormatter’s numberFormatter()’s setLocale:(current application’s NSLocale’s localeWithLocaleIdentifier:"ja") jpnMFormatter’s setUnitStyle:(current application’s NSFormattingUnitStyleLong) –NSFormattingUnitStyleShort, NSFormattingUnitStyleMedium, NSFormattingUnitStyleLong set j1Res to (jpnMFormatter’s stringFromKilograms:85) as string –Kg –> "85キログラム" set j2Res to (jpnMFormatter’s stringFromValue:1 unit:(current application’s NSMassFormatterUnitGram)) as string –g –> "1グラム" set j3Res to (jpnMFormatter’s stringFromValue:1 unit:(current application’s NSMassFormatterUnitOunce)) as string –オンス –> "1オンス" set j4Res to (jpnMFormatter’s stringFromValue:1 unit:(current application’s NSMassFormatterUnitStone)) as string –ストーン(=14 pounds) –> "1ストーン |
ローカライズドな度量衡表示(長さ)
AppleScript名:ローカライズドな度量衡表示(長さ) |
— Created 2015-11-20 by Shane Stanley — Modified 2016-01-14 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" –Length set engLFormatter to current application’s NSLengthFormatter’s alloc()’s init() engLFormatter’s numberFormatter()’s setLocale:(current application’s NSLocale’s localeWithLocaleIdentifier:"en-US") engLFormatter’s setUnitStyle:(current application’s NSFormattingUnitStyleLong) –NSFormattingUnitStyleShort, NSFormattingUnitStyleMedium, NSFormattingUnitStyleLong set a1Res to (engLFormatter’s stringFromMeters:85) as string –m –> "92.956 yards" set a2Res to (engLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitMillimeter)) as string –mm –> "1 millimeter" set a3Res to (engLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitCentimeter)) as string –cm –> "1 centimeter" set a4Res to (engLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitMeter)) as string –m –> "1 meter" set a5Res to (engLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitKilometer)) as string –Km –> "1 kilometer" set a6Res to (engLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitInch)) as string –inch –> "1 inch" set a7Res to (engLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitFoot)) as string –feet –> "1 foot" set a8Res to (engLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitYard)) as string –Yard –> "1 yard" set a9Res to (engLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitMile)) as string –Mile –> "1 mile" set jpnLFormatter to current application’s NSLengthFormatter’s alloc()’s init() jpnLFormatter’s numberFormatter()’s setLocale:(current application’s NSLocale’s localeWithLocaleIdentifier:"ja") jpnLFormatter’s setUnitStyle:(current application’s NSFormattingUnitStyleLong) –NSFormattingUnitStyleShort, NSFormattingUnitStyleMedium, NSFormattingUnitStyleLong set j1Res to (jpnLFormatter’s stringFromMeters:85) as string –m –> "85メートル" set j2Res to (jpnLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitMillimeter)) as string –mm –> "1ミリメートル" set j3Res to (jpnLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitCentimeter)) as string –cm –> "1センチメートル" set j4Res to (jpnLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitMeter)) as string –m –> "1メートル" set j5Res to (jpnLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitKilometer)) as string –Km –> "1キロメートル" set j6Res to (jpnLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitInch)) as string –inch –> "1インチ" set j7Res to (jpnLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitFoot)) as string –feet –> "1フィート" set j8Res to (jpnLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitYard)) as string –Yard –> "1ヤード" set j9Res to (jpnLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitMile)) as string –Mile –> "1マイル" |
ローカライズドな度量衡変換(lengthFormatter)
AppleScript名:ローカライズドな度量衡変換(lengthFormatter) |
— Created 2015-11-20 by Shane Stanley use AppleScript version "2.4" use scripting additions use framework "Foundation" set theNSMassFormatter to current application’s NSMassFormatter’s alloc()’s init() theNSMassFormatter’s numberFormatter()’s setLocale:(current application’s NSLocale’s localeWithLocaleIdentifier:"en-US") theNSMassFormatter’s setUnitStyle:(current application’s NSFormattingUnitStyleLong) (theNSMassFormatter’s stringFromKilograms:85) as list of string or string log result –> "187.393 pounds" (theNSMassFormatter’s stringFromValue:1 unit:(current application’s NSMassFormatterUnitGram)) as list of string or string log result –> "1 gram" set theNSLengthFormatter to current application’s NSLengthFormatter’s alloc()’s init() theNSLengthFormatter’s numberFormatter()’s setLocale:(current application’s NSLocale’s localeWithLocaleIdentifier:"ja") theNSLengthFormatter’s setUnitStyle:(current application’s NSFormattingUnitStyleLong) (theNSLengthFormatter’s stringFromMeters:1) as list of string or string log result –> "100センチメートル"–We usually use "100cm" in Japanese. (theNSLengthFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitFoot)) as list of string or string log result –> "1フィート" |
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: |
現在の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 |
数値文字列に対して、少数点以下の数値の切り上げ、切り下げ 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 |
数値書式関連
AppleScript名:数値書式関連 |
use AppleScript version "2.4" use framework "Foundation" use scripting additions set theNumber to 1.234567890123E+12 set theResult to formatNumber_(theNumber) –> "1,234,567,890,123" set aRes to textFromNumber_forLocale_(1.2345678E+4, "fr") –> "douze-mille-trois-cent-quarante-cinq virgule six sept huit" set aRes to textFromNumber_forLocale_(1.2345678E+4, "ja") –> "一万二千三百四十五・六七八" set aRes to formatNumber_usingFormat_(1.2345678E+4, "#,###.00;0.00;(#,##0.00)") –> "12,345.68" on formatNumber:theNumber set theFormatter to current application’s NSNumberFormatter’s new() theFormatter’s setNumberStyle:(current application’s NSNumberFormatterDecimalStyle) set theResult to theFormatter’s stringFromNumber:theNumber return theResult as text end formatNumber: on textFromNumber:theNumber forLocale:localeString set theFormatter to current application’s NSNumberFormatter’s new() theFormatter’s setNumberStyle:(current application’s NSNumberFormatterSpellOutStyle) set theLocale to current application’s NSLocale’s localeWithLocaleIdentifier:localeString theFormatter’s setLocale:theLocale set theResult to theFormatter’s stringFromNumber:theNumber return theResult as text end textFromNumber:forLocale: on formatNumber:theNumber usingFormat:formatString set theFormatter to current application’s NSNumberFormatter’s new() theFormatter’s setFormat:formatString theFormatter’s setLocalizesFormat:false set theResult to theFormatter’s stringFromNumber:theNumber return theResult as text end formatNumber:usingFormat: |