AppleScript名:液体の容積の単位変換 |
–液体の容積の単位変換 set a to 10 as liters –> liters 10.0 set b to a as gallons –> gallons 2.641720372842 set c to a as quarts –> quarts 10.566881491367 |
タグ: 10.13savvy
最小公倍数(LCM)を求める v3
AppleScript名:最小公倍数を求める v3 |
— Created 2017-05-20 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "primeNumKit" –https://github.com/NazarYavornytskyy/prime-number-objc set a1Num to 75 set b1Num to 315 set cRes to getLCMbetweenTwoNums(a1Num, b1Num) of me –> 1575 –2つの数の最小公倍数を求める on getLCMbetweenTwoNums(a1Num, b1Num) set aGCD to getGCDbetweenTwoNums(a1Num, b1Num) of me set a2Num to a1Num div aGCD set b2Num to b1Num div aGCD return (aGCD * a2Num * b2Num) end getLCMbetweenTwoNums –2つの数の最大公約数を求める on getGCDbetweenTwoNums(aNum, bNum) set aRes to getPrimeFactor(aNum) of me set bRes to getPrimeFactor(bNum) of me –2つのリストを集合として扱い、積集合を求める set aSet to current application’s NSMutableSet’s setWithArray:aRes set bSet to current application’s NSMutableSet’s setWithArray:bRes aSet’s intersectSet:bSet set cRes to aSet’s allObjects() as list set dRes to multipleListElements(cRes) of me return dRes end getGCDbetweenTwoNums –与えられた数を素因数分解する on getPrimeFactor(aTargNum) copy aTargNum to a set pFactList to {} repeat set pRes to checkPrimeNumber(a) of me if pRes = true then set the end of pFactList to a return pFactList end if set aFactor to checkFactor(a) of me set the end of pFactList to aFactor set a to a div aFactor end repeat end getPrimeFactor –素数チェック on checkPrimeNumber(aNum) if aNum < 10000 then –0.25秒以上かかりそうな処理はCocoaで処理(実測値ベース) return checkPrimeNumberSub1(aNum) of me else set aPrime to current application’s PrimeNumberHelper’s alloc()’s init() return (aPrime’s isPrime:aNum) as boolean end if end checkPrimeNumber –小さい数の場合の素数検出 on checkPrimeNumberSub1(aNum) repeat with i from 2 to (aNum div 2) if aNum mod i is equal to 0 then return i –false end if end repeat return true end checkPrimeNumberSub1 –素因数チェック on checkFactor(aNum) repeat with i from 2 to (aNum div 2) if aNum mod i is equal to 0 then return i end if end repeat end checkFactor –リスト内の要素をすべて乗算する on multipleListElements(aList) set aNum to 1 set aRes to 1 repeat with i in aList set aRes to aRes * (aNum * i) end repeat return aRes end multipleListElements |
最大公約数(GCD)を求めるv4
AppleScript名:最大公約数を求めるv4 |
— Created 2017-05-20 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "primeNumKit" –https://github.com/NazarYavornytskyy/prime-number-objc set aRes to getGCDbetweenTwoNums(75, 315) of me –> 15 –2つの数の最大公約数を求める on getGCDbetweenTwoNums(aNum, bNum) set aRes to getPrimeFactor(aNum) of me set bRes to getPrimeFactor(bNum) of me –2つのリストを集合として扱い、積集合を求める set aSet to current application’s NSMutableSet’s setWithArray:aRes set bSet to current application’s NSMutableSet’s setWithArray:bRes aSet’s intersectSet:bSet set cRes to aSet’s allObjects() as list set dRes to multipleListElements(cRes) of me return dRes end getGCDbetweenTwoNums –与えられた数を素因数分解する on getPrimeFactor(aTargNum) copy aTargNum to a set pFactList to {} repeat set pRes to checkPrimeNumber(a) of me if pRes = true then set the end of pFactList to a return pFactList end if set aFactor to checkFactor(a) of me set the end of pFactList to aFactor set a to a div aFactor end repeat end getPrimeFactor –素数チェック on checkPrimeNumber(aNum) if aNum < 10000 then –0.25秒以上かかりそうな処理はCocoaで処理(実測値ベース) return checkPrimeNumberSub1(aNum) of me else set aPrime to current application’s PrimeNumberHelper’s alloc()’s init() return (aPrime’s isPrime:aNum) as boolean end if end checkPrimeNumber –小さい数の場合の素数検出 on checkPrimeNumberSub1(aNum) repeat with i from 2 to (aNum div 2) if aNum mod i is equal to 0 then return i –false end if end repeat return true end checkPrimeNumberSub1 –素因数チェック on checkFactor(aNum) repeat with i from 2 to (aNum div 2) if aNum mod i is equal to 0 then return i end if end repeat end checkFactor –リスト内の要素をすべて乗算する on multipleListElements(aList) set aNum to 1 set aRes to 1 repeat with i in aList set aRes to aRes * (aNum * i) end repeat return aRes end multipleListElements |
Keynoteでタイトルがマスターに入っていなかった場合に修正 v2
Keynoteのタイトルがマスターに入っていなかった場合に、スライドの一番左上に存在するテキストアイテムをタイトルに入れ直すAppleScriptです。
Keynoteで急いでスライドを作ってはみたものの、あわててタイトルをマスタースライドのタイトルオブジェクトに入れていなかった場合に、(見た目は変わらないものの)あとで修正しておく必要があるケースがあります(Keynoteのデータを再利用するような場合とか)。
そこで、現在表示中のスライド中で一番左上に存在するテキストアイテムで、フォントサイズ20ポイント以上、文字色が黒 {0, 0, 0} のものをタイトルとみなして、文字を取得。あらためてマスタースライドのタイトルオブジェクトに文字を入れ直します。
このままだと、色データが{0,0,1}になったぐらいで検出できなくなってしまいますが、Color Domain処理を組み合わせることで「だいたい黒」「黒っぽい色」といった判定が行えるため、組み合わせて使うと効果的でしょう。
▲Before
▲After
AppleScript名:Keynoteでタイトルがマスターに入っていなかった場合に矯正 v2 |
use AppleScript version "2.4" use framework "Foundation" use scripting additions use bPlus : script "BridgePlus" property minTitleFontSize : 20 property targBaseSlide : "タイトル(上)" tell application "Keynote" tell front document set newMaster to master slide targBaseSlide tell current slide set curBaseName to name of base slide –現在のスライド上のすべてのテキストアイテムの座標{x ,y}を取得して最小(一番上)のものを推測 set pList to position of every text item set p2List to sort2DListAscending(pList) of me set mostUpPos to contents of first item of p2List –一番上に存在するテキストアイテムから情報を抽出 set tTextItem to first item of (every text item whose position is mostUpPos) tell tTextItem set tObjText to (object text) set aTitle to tObjText as string set aProp to size of (object text) set aColor to color of (object text) end tell –スライドの一番上に存在するテキストアイテムのフォントサイズが想定以上で、色が黒の場合には –マスタースライドのデフォルトタイトルに、一番上に存在していたテキストアイテムの本文を突っ込む if (aProp ≥ minTitleFontSize) and (aColor = {0, 0, 0}) then –色判定でColor Domain処理を行えば、「黒っぽい色」や「赤っぽい色」を対象にできる if curBaseName is not equal to targBaseSlide then set base slide to newMaster end if delete tTextItem set object text of default title item to aTitle end if end tell end tell end tell –2D Listのソート on sort2DListAscending(aList) load framework set sortIndexes to {0, 1} –Key Item id: begin from 0 set sortOrders to {true, true} –Ascending, Ascending set sortTypes to {"compare:", "compare:"} set bList to (current application’s SMSForder’s subarraysIn:(aList) sortedByIndexes:sortIndexes ascending:sortOrders sortTypes:sortTypes |error|:(missing value)) return bList as list of string or string end sort2DListAscending |
Finder Windowを円運動 v4
Finderのウィンドウ6つ(可変)を画面上で別々に楕円運動させるAppleScriptです。
三角関数の計算にShane StanleyのBridge Plus AppleScript Librariesを利用しています。
AppleScript名:Finder Windowを円運動 v4 |
— Created 2014-11-17 by Takaaki Naganoya — Modified 2018-02-23 by Takaaki Naganoya — 2014-2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" — for NSScreen use bPlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html property aNum : 300 property aOffset : 0 property maxWin : 6 property winList : {} property randList : {} property winSize : 300 –Initialize load framework set winList to {} set randList to {} repeat maxWin times tell application "Finder" activate set aWin to make new Finder window tell aWin set toolbar visible to false set sidebar width to 0 set statusbar visible to false set position to {100, 100} set bounds to {100, 100, 100 + winSize, 100 + winSize} end tell set the end of winList to aWin set the end of randList to {random number from 0 to 400, random number from 0 to 400, random number from 1 to 360} end tell end repeat –Main repeat with i from 1 to 360 by 6 repeat with ii from 1 to maxWin set aWinObj to contents of item ii of winList set {aRandX, aRandY, aRandDegree} to item ii of randList set aDeg to i + aRandDegree set aSinNum to (current application’s SMSForder’s sinValueOf:aDeg) as real set aCosNum to (current application’s SMSForder’s cosValueOf:aDeg) as real set x to ((aNum * aSinNum) + aNum) * 2 + aOffset set y to (aNum * aCosNum) + aNum + aOffset ignoring application responses tell application "Finder" tell aWinObj set position to {(x as integer) + aRandX, (y as integer) + aRandY} end tell end tell end ignoring end repeat end repeat –Sweep tell application "Finder" repeat with i in winList tell i close end tell end repeat end tell |
Finder Windowを円運動 v1b
Finderのウィンドウ1つを画面上で楕円運動させるAppleScriptです。
三角関数の計算にShane StanleyのBridge Plus AppleScript Librariesを利用しています。
以前に掲載したバージョン(v1)から、BridgePlusを使うように変更しました。
自分が最初に見たAppleScriptが、「AppleScript道入門」に掲載されていたテキストエディタのウィンドウを画面の淵に沿わせて直線移動で1周させるものでした(それを見て「たいしたことはない」と思ってしまいましたが)。
いまでは、楕円軌道に沿ったウィンドウ移動もこのぐらいのスピードでできている、ということを実感できました。
AppleScript名:Finder Windowを円運動 v1b |
use AppleScript version "2.4" use scripting additions use framework "Foundation" use bPlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html use framework "AppKit" — for NSScreen property aNum : 300 property aOffset : 0 load framework set {newX, newY} to (current application’s NSScreen’s mainScreen()’s frame()’s |size|()) as list tell application "Finder" set aWin to make new Finder window end tell repeat with i from 1 to 360 by 6 set |asin| to (current application’s SMSForder’s sinValueOf:i) as real set |acos| to (current application’s SMSForder’s cosValueOf:i) as real set x to ((aNum * |asin|) + aNum) * 2.0 + aOffset set y to (aNum * |acos|) + aNum + aOffset tell application "Finder" tell aWin set position to {x as integer, y as integer} end tell end tell end repeat tell application "Finder" tell aWin close end tell end tell |
テーマを選択してKeynoteの新規ドキュメントを作成
AppleScript名:テーマを選択してKeynoteの新規ドキュメントを作成 |
tell application "Keynote" set tList to name of every theme set themeName to first item of (choose from list tList) set newDoc to make new document with properties {document theme:theme themeName} end tell |
Keynote 6.6でドキュメントを新規作成して指定可能なマスタースライド一覧を取得
AppleScript名:Keynote 6.6でドキュメントを新規作成して指定可能なマスタースライド一覧を取得 |
— Created 2015-10-27 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" tell application "Keynote" –Keynoteの用語辞書のサンプルどおりに書いても動かない!!(オブジェクト名がローカライズされているので、テーマ名が言語環境依存) set aDoc to (make new document with properties {document theme:theme "ホワイト", width:1920, height:1080}) tell aDoc set masList to name of every master slide –> {"タイトル & サブタイトル", "画像(横長)", "タイトル(中央)", "画像(縦長)", "タイトル(上)", "タイトル & 箇条書き", "タイトル、箇条書き、画像", "箇条書き", "画像(3 点)", "引用", "写真", "空白"} end tell end tell |
Keynoteで現在表示中のスライド上にある表のカラム幅を自動調整
▲Before
▲After
AppleScript名:Keynoteで現在表示中のスライド上にある表のカラム幅を自動調整 v2 |
— Created 2017-10-06 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" tell application "Keynote" tell front document tell current slide set tCount to count every table if tCount = 0 then return tell table 1 set cCount to count every column set cWidth to width of every column set aWidth to width –table width set aveWidth to (aWidth – (first item of cWidth)) / (cCount – 1) tell columns 2 thru cCount set width to aveWidth end tell end tell end tell end tell end tell |
Keynoteで2D円グラフを作成
Keynoteの現在の書類上に2D円グラフを作成するAppleScriptです。
その他、さまざまなKeynote上で作成可能なグラフを作成するAppleScriptについては、電子書籍「Keynote Control with AppleScript」❶❷で解説しています。
AppleScript名:Keynoteで2D円グラフを作成 |
–set aRec to {kanjiNum:24960, kanjiRating:28.0, hiraganaNum:56080, hiraganaRating:62.9, katakanaNum:1063, katakanaRating:1.2, otherNum:7136, otherRating:8.0} –文学(坊ちゃん) –set aRec to {kanjiNum:563289, kanjiRating:22.0, hiraganaNum:1311933, hiraganaRating:51.2, katakanaNum:210161, katakanaRating:8.2, otherNum:478690, otherRating:18.7, totalCount:2564073}–異世界はスマートフォンとともに set aRec to {kanjiNum:364870, kanjiRating:26.7, hiraganaNum:682261, hiraganaRating:50.0, katakanaNum:89109, katakanaRating:6.6, otherNum:230374, otherRating:16.9, totalCount:1366614} –Knight’s and Magic set cCount to (kanjiNum of aRec) set hCount to (hiraganaNum of aRec) set kCount to (katakanaNum of aRec) set oCount to (otherNum of aRec) tell application "Keynote" set aDoc to (make new document with properties {document theme:theme "ホワイト", width:1024, height:768}) –Normal Slide –set aDoc to (make new document with properties {document theme:theme "ホワイト", width:1920, height:1080})–Wide Slide tell front document set aSlide to make new slide at after (first slide) with properties {base slide:master slide "タイトル(上)"} tell aSlide set object text of default title item to "文字種別使用比率" –add chart row names {"文字種別"} column names {"漢字", "ひらがな", "カタカナ", "その他"} data {{cCount, hCount, kCount, oCount}} type pie_2d –group by chart row add chart row names {"文字種別"} column names {"Kanji", "Hiragana", "Katakana", "Other"} data {{cCount, hCount, kCount, oCount}} type pie_2d –group by chart row end tell end tell end tell |
NSCountedSetでNSDictionaryの登場頻度集計 v2
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 |
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 |