AppleScript名:ASOCでNSPredicateによる正規表現を併用した抽出 |
— Created 2015-09-28 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use BridgePlus : script "BridgePlus" —https://www.macosxautomation.com/applescript/apps/BridgePlus.html set sampleList to {{textData:"Piyomaru", uID:1}, {textData:"Xx Piyomaru x", uID:2}, {textData:"xxxxx 11111111 98 x xxxxxxxx.", uID:3}, {textData:"98x Xxxxxx (xx xxxxxxxxxx)", uID:4}, {textData:"<< 98158113 >>", uID:5}, {textData:"#98158084 Xxxxx Xxxxx xxxx", uID:6}, {textData:"#98158084 Xxxxx Xxxxx xxxx", uID:7}, {textData:"Office # 98158107", uID:8}, {textData:"ID#98158087", uID:9}, {textData:"98158089", uID:10}, {textData:"00158098", uID:11}} –全文一致で抽出 set aRes to my filterRecListByLabel1(sampleList, "textData == ’Piyomaru’") –> {{textData:"Piyomaru", uID:1}} –部分一致で抽出 set bRes to my filterRecListByLabel1(sampleList, "textData contains ’Piyomaru’") –> {{textData:"Piyomaru", uID:1}, {textData:"Xx Piyomaru x", uID:2}} –正規表現で抽出(8桁の数字) set cRes to my filterRecListByLabel1(sampleList, "textData MATCHES ’\\\\d{8}’") –> {{textData:"98158089", uID:10}, {textData:"00158089", uID:11}} set dRes to my filterRecListByLabel1(sampleList, "textData MATCHES ’98\\\\d{6}’") –> {{textData:"98158089", uID:10}} set eRes to my filterRecListByLabel1(sampleList, "textData LIKE ’*98??????*’") –> {{textData:"xxxxx 11111111 98 x xxxxxxxx.", uID:3}, {textData:"98x Xxxxxx (xx xxxxxxxxxx)", uID:4}, {textData:"<< 98158113 >>", uID:5}, {textData:"#98158084 Xxxxx Xxxxx xxxx", uID:6}, {textData:"#98158084 Xxxxx Xxxxx xxxx", uID:7}, {textData:"Office # 98158107", uID:8}, {textData:"ID#98158087", uID:9}, {textData:"98158089", uID:10}} set fRes to my filterRecListByLabel1(sampleList, "textData LIKE ’*\"98\"[0-9][0-9][0-9][0-9][0-9][0-9]*’") –Oops!! –> {} set gRes to my filterRecListByLabel1(sampleList, "textData LIKE ’*[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*’") –Oops!! –> {} set hRes to my filterRecListByLabel1(sampleList, "textData MATCHES ’.*[98]\\\\d{6}.*’") –OK!! –> {{textData:"<< 98158113 >>", uID:5}, {textData:"#98158084 Xxxxx Xxxxx xxxx", uID:6}, {textData:"#98158084 Xxxxx Xxxxx xxxx", uID:7}, {textData:"Office # 98158107", uID:8}, {textData:"ID#98158087", uID:9}, {textData:"98158089", uID:10}} –リストに入れたレコードを、指定の属性ラベルの値で抽出 on filterRecListByLabel1(aRecList as list, aPredicate as string) set aArray to current application’s NSArray’s arrayWithArray:aRecList set aPredicate to current application’s NSPredicate’s predicateWithFormat:aPredicate set filteredArray to aArray’s filteredArrayUsingPredicate:aPredicate set bList to ASify from filteredArray as list return bList end filterRecListByLabel1 |
タグ: 10.11savvy
リストに入れたレコードを、指定の属性ラベルの値で抽出
AppleScript名:リストに入れたレコードを、指定の属性ラベルの値で抽出 |
— Created 2017-03-16 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aList to {{aLabel:"1", bLabel:"1"}, {aLabel:"2", bLabel:"2"}, {aLabel:"3", bLabel:"3"}, {aLabel:"4", bLabel:"4"}} set anArray to current application’s NSMutableArray’s arrayWithArray:aList set aRes to my filterRecListByLabel1(anArray, "aLabel == ’1’") –> {{aLabel:"1", bLabel:"1"}} –リストに入れたレコードを、指定の属性ラベルの値で抽出 on filterRecListByLabel1(aRecList as list, aPredicate as string) set aArray to current application’s NSArray’s arrayWithArray:aRecList set aPredicate to current application’s NSPredicate’s predicateWithFormat:aPredicate set filteredArray to aArray’s filteredArrayUsingPredicate:aPredicate return filteredArray as list end filterRecListByLabel1 |
ASOCでレコードのリストから抽出
AppleScript名:ASOCでレコードのリストから抽出 |
— Created 2017-08-05 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set dList to {{deviceName:"Piyomaru AirPods", deviceAddress:"7c-04-d0-8b-bc-fb"}, {deviceName:"Takaaki Naganoya のマウス", deviceAddress:"ac-bc-32-dd-99-3e"}, {deviceName:"Takaaki Naganoya のキーボード #1", deviceAddress:"04-69-f8-be-2a-c7"}} set dRes to filterRecListByLabel(dList, "deviceName contains ’AirPods’") of me if dRes = {} then return false –Case: No match set dAddr to dRes’s first item’s deviceAddress return dAddr –リストに入れたレコードを、指定の属性ラベルの値で抽出 on filterRecListByLabel(aRecList as list, aPredicate as string) –ListからNSArrayへの型変換 set aArray to current application’s NSArray’s arrayWithArray:aRecList –抽出 set aPredicate to current application’s NSPredicate’s predicateWithFormat:aPredicate set filteredArray to aArray’s filteredArrayUsingPredicate:aPredicate –NSArrayからListに型変換して返す set bList to filteredArray as list return bList end filterRecListByLabel |
レコードとレコードの連結
AppleScript名:レコードとレコードの連結 |
–Case: same label (fullName) and same value ("abc") set aRec to {fullName:"abc", anAge:46} set bRec to {fullName:"abc", aInfo:10} set cRec to aRec & bRec –> {fullName:"abc", anAge:46, aInfo:10} –Case: same label (fullName) and different value ("abc", "def") set dRec to {fullName:"abc", anAge:46} set eRec to {fullName:"def", aInfo:10} set fRec to dRec & eRec –> {fullName:"abc", anAge:46, aInfo:10} set gRec to eRec & dRec –> {fullName:"def", aInfo:10, anAge:46} |
指定ラベルと指定属性値でレコードに追加
AppleScript名:指定ラベルと指定属性値でレコードに追加 |
— Created 2017-03-16 11:51:08 +0900 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aRec to {f1:"1", f2:"2", f3:"3"} set bRec to addValueForKey(aRec, "100", "f10") of me –> {f1:"1", f3:"3", f10:"100", f2:"2"} on addValueForKey(aRec, aVal, aKey) set aDict to current application’s NSMutableDictionary’s dictionaryWithDictionary:aRec aDict’s addObject:aVal forKey:aKey return aDict as record end addValueForKey |
ASOCでDict読み込みして、指定のMSの搭乗回数を取得する v2
AppleScript名:ASOCでDict読み込みして、指定のMSの搭乗回数を取得する v2 |
use AppleScript version "2.4" use scripting additions use framework "Foundation" set aName to "efsf.plist" set aFolName to "戦場の絆" set aRec to retDictFromPlist(aFolName, aName) of me set msL to msList of aRec set eList to filterRecListByLabel(msL, "msName CONTAINS ’近 ザクII(F2) 獲得済’") of me set aTimes to sortieTimes of first item of eList on retDictFromPlist(aFolName, aPlistName) set myAppSupDir to ((path to application support from user domain) as string) & aFolName & ":" tell application "System Events" –Finderでなくこちらを使ってみた tell folder myAppSupDir set aExit to exists of file aPlistName end tell end tell if aExit = false then return {} else set aPath to (POSIX path of myAppSupDir) & aPlistName set thePath to current application’s NSString’s stringWithString:aPath set thePath to thePath’s stringByExpandingTildeInPath() set theDict to current application’s NSDictionary’s dictionaryWithContentsOfFile:thePath return theDict as record end if end retDictFromPlist –リストに入れたレコードを、指定の属性ラベルの値で抽出 on filterRecListByLabel(aRecList as list, aPredicate as string) –ListからNSArrayへの型変換 set aArray to current application’s NSArray’s arrayWithArray:aRecList –抽出 set aPredicate to current application’s NSPredicate’s predicateWithFormat:aPredicate set filteredArray to aArray’s filteredArrayUsingPredicate:aPredicate –NSArrayからListに型変換して返す set bList to filteredArray as list return bList end filterRecListByLabel |
ASOCでDict書き込み_3(Bridge Plus)
AppleScript名:ASOCでDict書き込み_3(Bridge Plus) |
use AppleScript version "2.4" use framework "Foundation" use scripting additions use script "BridgePlus" — https://www.macosxautomation.com/applescript/apps/BridgePlus.html load framework — BridgePlus command to load set a1List to {"msName", "sortieTimes"} set b1List to {{"近 装甲強化型ジム 獲得済 COST: 200", 66}, {"遠 ジム・キャノン 獲得済 COST: 160", 43}, {"近 ザクII(F2) 獲得済 COST: 160", 42}, {"近 ジム・コマンド 獲得済 COST: 200", 32}, {"近 ジム(WD隊) 獲得済 COST: 160", 28}, {"近 陸戦型ガンダム 獲得済 COST: 220", 24}, {"近 ジム改 獲得済 COST: 240", 22}, {"遠 ガンタンク 獲得済 COST: 200", 22}, {"格 ジム(指揮官機) 獲得済 COST: 160", 20}, {"近 ジム 獲得済 COST: 120", 19}, {"遠 量産型ガンタンク 獲得済 COST: 160", 14}, {"格 陸戦型ジム 獲得済 COST: 120", 12}, {"格 ガンダム 獲得済 COST: 280", 11}, {"近 ジム・トレーナー 獲得済 COST: 120", 9}, {"射 ジム・スナイパーII(WD隊) 獲得済 COST: 220", 9}, {"射 陸戦型ガンダム(ジム頭) 獲得済 COST: 200", 7}, {"格 ガンダムEz8 獲得済 COST: 240", 6}, {"近 ジム・寒冷地仕様 獲得済 COST: 200", 6}, {"狙 ジム・スナイパーカスタム 獲得済 COST: 200", 6}, {"格 ジム・ストライカー 獲得済 COST: 180", 4}, {"格 ガンキャノン重装型 獲得済 COST: 160", 3}, {"近 アクア・ジム 獲得済 COST: 160", 2}, {"射 ガンキャノン 獲得済 COST: 200", 2}, {"近 ジム・コマンドライトアーマー 獲得済 COST: 160", 1}, {"格 ボールK型 獲得済 COST: 120", 0}, {"格 B.D.2号機 獲得済 COST: 260", 0}, {"格 プロトタイプガンダム 獲得済 COST: 280", 0}, {"近 パワード・ジム 獲得済 COST: 240", 0}, {"射 デザート・ジム 獲得済 COST: 160", 0}, {"遠 量産型ガンキャノン 獲得済 COST: 200", 0}} — BridgePlus uses SMSForder instead of SMSFord in ASOBjCExtras, but method is the same set aArray to current application’s SMSForder’s subarraysIn:b1List asDictionariesUsingLabels:a1List |error|:(missing value) set cRec to {msList:aArray, sortieDate:date string of (current date)} set aName to "efsf.plist" saveRecordToFolAsPlist(cRec, "戦場の絆", aName) of me on saveRecordToFolAsPlist(theRecord, folName, aName) set myAppSupDir to POSIX path of (path to application support from user domain) set folderURL to (current application’s class "NSURL"’s fileURLWithPath:myAppSupDir)’s URLByAppendingPathComponent:folName –do shell script(mkdir -p)のかわりに、指定ディレクトリまで作成 current application’s NSFileManager’s defaultManager()’s createDirectoryAtURL:folderURL withIntermediateDirectories:true attributes:(missing value) |error|:(missing value) set theDict to current application’s NSDictionary’s dictionaryWithDictionary:theRecord set aRes to theDict’s writeToURL:(folderURL’s URLByAppendingPathComponent:aName) atomically:true return aRes as boolean end saveRecordToFolAsPlist |
ASOCでレコードのリストをユニーク化
AppleScript名:ASOCでレコードのリストをユニーク化 |
use AppleScript version "2.4" use framework "Foundation" use scripting additions set msRecList to {{msName:"格 陸戦型ジム 獲得済 COST: 120", sortieTimes:12}, {msName:"狙 ジム・スナイパーカスタム 獲得済 COST: 200", sortieTimes:6}, {msName:"狙 ジム・スナイパーカスタム 獲得済 COST: 200", sortieTimes:6}} set newMsList to uniquefyList(msRecList) –> {{sortieTimes:6, msName:"狙 ジム・スナイパーカスタム 獲得済 COST: 200"}, {sortieTimes:12, msName:"格 陸戦型ジム 獲得済 COST: 120"}} –レコードのリストをユニーク化 on uniquefyList(aList) set msArray to current application’s NSArray’s arrayWithArray:aList set aRes to current application’s NSSet’s setWithArray:(msArray’s allObjects()) set bRes to aRes’s allObjects() set cRes to bRes as list return cRes end uniquefyList |
なんでもデータを文字列化 v2
数値でもリストでもレコードでもなんでも文字列化するAppleScriptです。
大規模なシステムを作っているときに、ログに詳細なデータを書き込む必要があって、その入り組んだrecordから各種要素を取り出すのが嫌だったので、「そのまま文字列化してしまえ」と考えて作成したものです。
エラートラップを仕掛けてわざとエラーを発生させ、エラーメッセージに表記されているデータを加工して出力するというトリッキーかつやけっぱちな処理内容ですが、たしかに動作し、日本語以外の言語環境でもきちんと動くためひそかに利用されている処理です。
ただし、本ルーチンではアプリケーションのオブジェクトを含むデータの文字列化が行えないので、のちになって作成したOSAScriptControllerで実際にAppleScriptを実行して結果をすべて文字列で取得するようなタイプのものに入れ替えています。
AppleScript名:なんでもデータを文字列化 v2 |
set a to {{aName:"PiyoPiyo", anAge:10}, {aName:"Piyoko", anAge:9}} –record in list –set a to {aName:"PiyoPiyo", anAge:10}–record –set a to {{1, 2, 3}, {4, 5, 6}}–list –set a to 1.0 as real–real –set a to 1 as integer–integer –set a to "1.0" as string–string –set a to true–boolean –set a to front window of application "Finder"–アプリケーションのオブジェクトはエラーになるよ! –set a to missing value set aRes to convToStr(a) of somethingToStrKit –> "{{aName:\"PiyoPiyo\", anAge:10}, {aName:\"Piyoko\", anAge:9}}" –リストでもレコードでもなんでも文字列化して返すキット script somethingToStrKit on convToStr(aRec) set aClass to (class of aRec) as string if (aClass = "integer") or (aClass = "number") or (aClass = "real") or (aClass = "string") or (aClass = "text") or (aClass = "Unicode text") or (aClass = "boolean") then set aRes to aRec as string else if aClass is "list" then set aRes to listToString(aRec) else if aClass is "record" then set aRes to recToString(aRec) else try set aRes to aRec as string on error –アプリケーションのオブジェクトとかはエラーで返す return false end try end if return aRes end convToStr –レコードをStringに変換 –エラートラップを使って、わざとエラーを発生させ、エラーメッセージからレコードをstringに変換する on recToString(aRec) –レコードを無理矢理stringにcastして、エラーメッセージを取得する try set a to aRec as string –ここでエラー発生 on error aMes set a to aMes end try –エラーメッセージ文字列から、元のレコードの情報を組み立てる set b to trimStrFromTo(a, "{", "}") set b to "{" & b & "}" return b end recToString 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 –リストおよびリストに入ったレコードをStringに変換 on listToString(aList) set listText to {"{"} set quotChar to ASCII character 34 set firstFlag to true repeat with i in aList set j to contents of i set aClass to (class of i) as string if (aClass = "integer") or (aClass = "number") or (aClass = "real") then set the end of listText to (getFirst(firstFlag) of me & j as text) set firstFlag to false else if (aClass = "string") or (aClass = "text") or (aClass = "Unicode text") then set the end of listText to ((getFirst(firstFlag) of me & quotChar & j as text) & quotChar) set firstFlag to false else if aClass is "list" then set the end of listText to (getFirst(firstFlag) & listToString(j)) –ちょっと再帰処理 set firstFlag to false else if aClass is "record" then set the end of listText to (getFirst(firstFlag) & recToString(j)) set firstFlag to false end if end repeat set the end of listText to "}" set listText to listText as text return listText end listToString on getFirst(aFlag) if aFlag = true then return "" if aFlag = false then return ", " end getFirst end script |
asoc_レコードのリストをソート
AppleScript名:asoc_レコードのリストをソート |
— Created 2017-05-22 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aList to {{theWord:"英国", retweetCount:0}, {theWord:"新潟記念", retweetCount:0}, {theWord:"一時的", retweetCount:0}, {theWord:"原宿", retweetCount:0}, {theWord:"経常収支", retweetCount:0}, {theWord:"板倉", retweetCount:0}, {theWord:"格安スマホ", retweetCount:0}, {theWord:"Wikileaks", retweetCount:0}, {theWord:"ジャニーズ事務所", retweetCount:0}, {theWord:"日産", retweetCount:0}, {theWord:"あずきバー", retweetCount:0}, {theWord:"海南省", retweetCount:0}, {theWord:"海外市場", retweetCount:0}, {theWord:"亀田劇場", retweetCount:0}, {theWord:"東芝", retweetCount:0}, {theWord:"南シナ海", retweetCount:0}, {theWord:"光害", retweetCount:0}, {theWord:"債務不履行", retweetCount:0}, {theWord:"BR", retweetCount:0}, {theWord:"大リーグ", retweetCount:0}, {theWord:"イスラム", retweetCount:0}, {theWord:"未来", retweetCount:0}, {theWord:"インプラント", retweetCount:0}, {theWord:"リーバイス", retweetCount:0}, {theWord:"スマホ", retweetCount:0}, {theWord:"ジル", retweetCount:0}, {theWord:"G7", retweetCount:0}, {theWord:"貿易統計", retweetCount:0}, {theWord:"宮崎県", retweetCount:0}, {theWord:"新基準", retweetCount:0}, {theWord:"福岡三越", retweetCount:0}, {theWord:"Croiseur Milan", retweetCount:0}, {theWord:"リスクオン", retweetCount:0}, {theWord:"異常接近", retweetCount:0}, {theWord:"キャッシング", retweetCount:0}, {theWord:"キレイだ", retweetCount:0}, {theWord:"HD", retweetCount:0}, {theWord:"高校野球", retweetCount:0}, {theWord:"田母神俊雄", retweetCount:0}, {theWord:"2月", retweetCount:0}, {theWord:"本田圭佑", retweetCount:0}, {theWord:"工藤静香", retweetCount:0}, {theWord:"大久保", retweetCount:0}, {theWord:"山東", retweetCount:0}, {theWord:"生中継", retweetCount:0}, {theWord:"有田哲平", retweetCount:0}, {theWord:"ジカ熱", retweetCount:0}, {theWord:"11月26日", retweetCount:0}, {theWord:"事実上", retweetCount:0}, {theWord:"英語表記", retweetCount:0}, {theWord:"文句なし", retweetCount:0}, {theWord:"糖質制限", retweetCount:0}, {theWord:"ベン", retweetCount:0}, {theWord:"監視社会", retweetCount:0}, {theWord:"三原じゅん子", retweetCount:0}, {theWord:"週刊ダイヤモンド", retweetCount:0}, {theWord:"スウェーデン", retweetCount:0}, {theWord:"赤ちゃんポスト", retweetCount:0}, {theWord:"20歳", retweetCount:0}, {theWord:"見聞録", retweetCount:0}, {theWord:"運動員", retweetCount:0}, {theWord:"liverty", retweetCount:0}, {theWord:"民進党", retweetCount:0}, {theWord:"ケー・エフ・シー", retweetCount:0}, {theWord:"ロシア当局", retweetCount:0}, {theWord:"拡張現実", retweetCount:0}, {theWord:"キスショット", retweetCount:0}, {theWord:"に学ぶ", retweetCount:0}, {theWord:"ASCII", retweetCount:0}, {theWord:"FOMC", retweetCount:0}, {theWord:"機関投資家", retweetCount:0}, {theWord:"労働法", retweetCount:0}, {theWord:"カンヌ映画祭", retweetCount:0}, {theWord:"賛否両論", retweetCount:0}, {theWord:"ユキ", retweetCount:0}, {theWord:"サウジ", retweetCount:0}, {theWord:"スカイツリー", retweetCount:0}, {theWord:"アリゲーターガー", retweetCount:0}, {theWord:"オフィスワーク", retweetCount:0}, {theWord:"アフガン", retweetCount:0}, {theWord:"北九州", retweetCount:0}, {theWord:"キリスト", retweetCount:0}, {theWord:"利上げ観測", retweetCount:0}, {theWord:"渋谷", retweetCount:0}, {theWord:"カナダ", retweetCount:0}, {theWord:"京大", retweetCount:0}, {theWord:"侵略者", retweetCount:0}, {theWord:"夏季五輪", retweetCount:0}, {theWord:"乾", retweetCount:0}, {theWord:"グラミー賞", retweetCount:3154}, {theWord:"トヨタショック", retweetCount:27716}, {theWord:"スペイン", retweetCount:57180}, {theWord:"ソ連崩壊", retweetCount:1028}, {theWord:"マイナス金利", retweetCount:11783}, {theWord:"Triumph", retweetCount:5955}, {theWord:"通信社", retweetCount:10379}, {theWord:"そのままで", retweetCount:8114}, {theWord:"高須", retweetCount:50330}, {theWord:"田口淳之介", retweetCount:30}, {theWord:"利下げ観測", retweetCount:0}, {theWord:"日本企業", retweetCount:109187}, {theWord:"日向夏", retweetCount:98639}, {theWord:"観光農園", retweetCount:2342}, {theWord:"ASEAN", retweetCount:267}, {theWord:"規制撤廃", retweetCount:2044}, {theWord:"国2", retweetCount:27669}, {theWord:"サラリーマン川柳", retweetCount:581}, {theWord:"株式相場", retweetCount:6}, {theWord:"ハラ", retweetCount:1010}, {theWord:"仙台", retweetCount:44049}, {theWord:"駐日大使", retweetCount:233}, {theWord:"有吉", retweetCount:267388}, {theWord:"英", retweetCount:22235}, {theWord:"一発逆転", retweetCount:2923}, {theWord:"北海道", retweetCount:8818}, {theWord:"3D", retweetCount:18976}, {theWord:"佐田建設", retweetCount:2901}, {theWord:"穏健派", retweetCount:4641}, {theWord:"聞く力", retweetCount:399}, {theWord:"火星探査機", retweetCount:1216}, {theWord:"ウォール街", retweetCount:1092}, {theWord:"Crowd Funding", retweetCount:6811}, {theWord:"赤羽", retweetCount:6874}, {theWord:"株高", retweetCount:28}, {theWord:"Pizza Hut", retweetCount:55727}, {theWord:"KAT-TUN", retweetCount:3330}, {theWord:"ドイツ", retweetCount:573124}, {theWord:"バルサ", retweetCount:4872}, {theWord:"SweetS", retweetCount:16952}, {theWord:"コミー", retweetCount:1305}, {theWord:"ご当地グルメ", retweetCount:1240}, {theWord:"アレグラ", retweetCount:0}, {theWord:"安倍首相", retweetCount:49530}, {theWord:"大腸がん", retweetCount:78}, {theWord:"業務提携", retweetCount:119}, {theWord:"米国", retweetCount:11739}, {theWord:"5日", retweetCount:18262}, {theWord:"総選挙", retweetCount:8269}, {theWord:"東武鉄道", retweetCount:963}, {theWord:"Samsung", retweetCount:20895}, {theWord:"RALPH LAUREN", retweetCount:7611}, {theWord:"ロ", retweetCount:4692}, {theWord:"ローソン", retweetCount:166787}, {theWord:"大嘘", retweetCount:8333}, {theWord:"森友", retweetCount:39699}, {theWord:"高島市", retweetCount:9868}, {theWord:"チワワ", retweetCount:9022}, {theWord:"栗原類", retweetCount:3020}, {theWord:"プラスワン", retweetCount:2299}, {theWord:"東大阪", retweetCount:5250}, {theWord:"政治学者", retweetCount:3365}, {theWord:"京", retweetCount:6701}, {theWord:"開催地", retweetCount:10018}, {theWord:"視聴率", retweetCount:20114}, {theWord:"大企業", retweetCount:11424}, {theWord:"近畿", retweetCount:4530}, {theWord:"石狩", retweetCount:145}, {theWord:"小田急", retweetCount:94364}, {theWord:"ベルーフ", retweetCount:12}, {theWord:"鉄道ジャーナル", retweetCount:970}, {theWord:"IT", retweetCount:437124}, {theWord:"公明党", retweetCount:2060}, {theWord:"表参道", retweetCount:18059}, {theWord:"経済成長", retweetCount:2257}, {theWord:"魚住りえ", retweetCount:25}, {theWord:"女子高生", retweetCount:512226}, {theWord:"野村", retweetCount:14080}, {theWord:"Google", retweetCount:1515}, {theWord:"NYダウ", retweetCount:253}, {theWord:"くりぃむ", retweetCount:5893}, {theWord:"博多", retweetCount:679890}, {theWord:"交通事故", retweetCount:3622}, {theWord:"就職四季報", retweetCount:0}, {theWord:"大統領制", retweetCount:3455}, {theWord:"トルコ", retweetCount:28673}, {theWord:"長野駅", retweetCount:11630}, {theWord:"繁華街", retweetCount:8179}, {theWord:"Deep Impact", retweetCount:10379}, {theWord:"ソニー", retweetCount:25410}, {theWord:"統一省", retweetCount:1250}, {theWord:"赤羽駅", retweetCount:9681}, {theWord:"U2", retweetCount:214}, {theWord:"日経ビジネス", retweetCount:4942}, {theWord:"日本人男性", retweetCount:6990}, {theWord:"キャサリン妃", retweetCount:1242}, {theWord:"重賞", retweetCount:670}, {theWord:"ニッポン", retweetCount:10690}, {theWord:"ブラジル", retweetCount:53316}, {theWord:"本部長", retweetCount:12333}, {theWord:"香川真司", retweetCount:28884}, {theWord:"金融市場", retweetCount:248}, {theWord:"万景峰号", retweetCount:2228}, {theWord:"W杯", retweetCount:9696}, {theWord:"北朝鮮", retweetCount:260562}, {theWord:"You Tube", retweetCount:70170}, {theWord:"橋本愛", retweetCount:4255}, {theWord:"日の丸半導体", retweetCount:464}, {theWord:"Enterprise", retweetCount:19289}, {theWord:"SNS", retweetCount:273982}, {theWord:"ヴェノム", retweetCount:18037}, {theWord:"インフレ率", retweetCount:5034}, {theWord:"アプリ", retweetCount:312863}, {theWord:"柴崎岳", retweetCount:1282}, {theWord:"独自制裁", retweetCount:1548}, {theWord:"弾道ミサイル", retweetCount:12150}, {theWord:"エジプト", retweetCount:55094}, {theWord:"日独", retweetCount:1528}, {theWord:"大分県警", retweetCount:1133}, {theWord:"ベルギー", retweetCount:29151}, {theWord:"労働組合", retweetCount:14314}, {theWord:"委員長", retweetCount:30619}, {theWord:"企業戦士", retweetCount:2749}, {theWord:"円高株安", retweetCount:18536}, {theWord:"下げ幅", retweetCount:56}, {theWord:"日本型", retweetCount:2164}, {theWord:"ペットショップ", retweetCount:7808}, {theWord:"イラン大統領", retweetCount:2817}, {theWord:"サマー2000シリーズ", retweetCount:0}, {theWord:"広尾", retweetCount:436}, {theWord:"本田翼", retweetCount:8313}, {theWord:"深読み", retweetCount:4269}, {theWord:"妖怪ウォッチ", retweetCount:5}, {theWord:"情報筋", retweetCount:7180}, {theWord:"液晶ディスプレイ", retweetCount:86}, {theWord:"ピッパ・ミドルトン", retweetCount:1255}, {theWord:"経済学", retweetCount:1208}, {theWord:"婚活", retweetCount:16789}, {theWord:"女子アナ", retweetCount:83}, {theWord:"SMAP", retweetCount:19538}, {theWord:"バフェット", retweetCount:466}, {theWord:"専門家", retweetCount:75824}, {theWord:"体験型", retweetCount:1906}, {theWord:"ラストチャンス", retweetCount:121140}, {theWord:"和歌山大", retweetCount:911}, {theWord:"通勤電車", retweetCount:3988}, {theWord:"ロス", retweetCount:1625}, {theWord:"駒の", retweetCount:515}, {theWord:"タカタ", retweetCount:36}, {theWord:"今季初", retweetCount:7164}, {theWord:"電子機器", retweetCount:585}, {theWord:"反政府デモ", retweetCount:762}, {theWord:"市場規模", retweetCount:288}, {theWord:"NY", retweetCount:377126}, {theWord:"鉄道事故", retweetCount:5084}, {theWord:"発達障害", retweetCount:46538}, {theWord:"コーセー", retweetCount:4444}, {theWord:"梅田", retweetCount:110569}, {theWord:"中国", retweetCount:69727}, {theWord:"埼玉", retweetCount:410646}, {theWord:"JR東海", retweetCount:227767}, {theWord:"雄二", retweetCount:2185}, {theWord:"不動産業", retweetCount:12112}, {theWord:"観測機", retweetCount:15345}, {theWord:"竹内結子", retweetCount:1727}, {theWord:"労基署", retweetCount:23756}, {theWord:"ホー", retweetCount:6316}, {theWord:"東洋経済オンライン", retweetCount:165}, {theWord:"EA", retweetCount:8341}, {theWord:"UZA", retweetCount:23153}, {theWord:"ロシア", retweetCount:729687}, {theWord:"環境相", retweetCount:9992}, {theWord:"過剰反応", retweetCount:381747}, {theWord:"イラン", retweetCount:9612}, {theWord:"フランス人", retweetCount:38565}, {theWord:"金融緩和", retweetCount:1261}, {theWord:"相鉄", retweetCount:1203}, {theWord:"ブレ", retweetCount:27000}, {theWord:"鑑定士", retweetCount:24350}, {theWord:"BOSS", retweetCount:273204}, {theWord:"IMF", retweetCount:0}, {theWord:"ポケ", retweetCount:0}, {theWord:"若い人", retweetCount:0}, {theWord:"準々決勝", retweetCount:0}, {theWord:"I-O DATA", retweetCount:0}, {theWord:"国際政治", retweetCount:0}, {theWord:"FRB", retweetCount:0}, {theWord:"NIKE", retweetCount:0}, {theWord:"警視庁", retweetCount:0}, {theWord:"ロイター", retweetCount:0}, {theWord:"FBI", retweetCount:0}, {theWord:"FBI", retweetCount:0}, {theWord:"エコカー", retweetCount:0}, {theWord:"働く男", retweetCount:0}, {theWord:"消費者", retweetCount:0}, {theWord:"旗艦店", retweetCount:0}, {theWord:"サービス業", retweetCount:0}, {theWord:"個人投資家", retweetCount:0}, {theWord:"エルドアン", retweetCount:0}, {theWord:"千葉テレビ", retweetCount:0}, {theWord:"首都圏", retweetCount:0}, {theWord:"蓮舫", retweetCount:0}, {theWord:"大幅続落", retweetCount:0}, {theWord:"字数制限", retweetCount:0}, {theWord:"国際テロ", retweetCount:0}, {theWord:"懐疑的", retweetCount:0}, {theWord:"日本", retweetCount:0}, {theWord:"環境省", retweetCount:0}, {theWord:"北極星", retweetCount:0}, {theWord:"カンボジア", retweetCount:0}, {theWord:"大統領選", retweetCount:0}, {theWord:"EU", retweetCount:0}, {theWord:"財務相", retweetCount:0}, {theWord:"武", retweetCount:0}, {theWord:"EV", retweetCount:0}, {theWord:"日銀", retweetCount:0}, {theWord:"DELI", retweetCount:0}, {theWord:"田母神", retweetCount:0}, {theWord:"スキー場", retweetCount:0}, {theWord:"スリーエフ", retweetCount:0}, {theWord:"創設者", retweetCount:0}, {theWord:"日本銀行", retweetCount:0}, {theWord:"政府広報", retweetCount:0}, {theWord:"米韓", retweetCount:0}, {theWord:"HONZ", retweetCount:0}, {theWord:"国交省", retweetCount:0}, {theWord:"青森山田", retweetCount:0}, {theWord:"下値余地", retweetCount:0}, {theWord:"学生野球", retweetCount:0}, {theWord:"都知事選", retweetCount:0}, {theWord:"受動喫煙", retweetCount:0}, {theWord:"体調不良", retweetCount:0}, {theWord:"バーガー", retweetCount:0}, {theWord:"2016年", retweetCount:0}, {theWord:"本田", retweetCount:0}, {theWord:"シュツットガルト", retweetCount:0}, {theWord:"日本郵政", retweetCount:0}, {theWord:"億万長者", retweetCount:0}, {theWord:"堀ちえみ", retweetCount:0}, {theWord:"近畿財務局", retweetCount:0}, {theWord:"日本株", retweetCount:0}, {theWord:"ラッカ", retweetCount:0}, {theWord:"中谷美紀", retweetCount:0}, {theWord:"ロシア経済", retweetCount:0}, {theWord:"決算説明会", retweetCount:0}, {theWord:"秋山進", retweetCount:0}, {theWord:"通勤時間", retweetCount:0}, {theWord:"三菱自", retweetCount:0}, {theWord:"マクロン", retweetCount:0}, {theWord:"バイロン・ネルソン", retweetCount:0}, {theWord:"浅香光代", retweetCount:0}, {theWord:"官房長官", retweetCount:0}, {theWord:"Halloween", retweetCount:0}, {theWord:"浅野", retweetCount:0}, {theWord:"東武", retweetCount:0}, {theWord:"ミサイル発射", retweetCount:0}, {theWord:"共同店舗", retweetCount:0}, {theWord:"西武", retweetCount:0}, {theWord:"大手私鉄", retweetCount:0}, {theWord:"食物繊維", retweetCount:0}, {theWord:"ガジェット", retweetCount:0}, {theWord:"民主党", retweetCount:0}, {theWord:"軍事衛星", retweetCount:0}, {theWord:"タカ派", retweetCount:0}, {theWord:"SIM", retweetCount:0}, {theWord:"原油価格", retweetCount:0}, {theWord:"電通", retweetCount:0}, {theWord:"早実", retweetCount:0}, {theWord:"株安", retweetCount:0}, {theWord:"共謀罪", retweetCount:0}, {theWord:"アンド", retweetCount:0}, {theWord:"芸能活動", retweetCount:0}, {theWord:"JR", retweetCount:0}, {theWord:"青山", retweetCount:0}, {theWord:"国連", retweetCount:0}, {theWord:"ウィリアム", retweetCount:0}, {theWord:"GDP", retweetCount:0}, {theWord:"南青山", retweetCount:0}, {theWord:"大阪", retweetCount:0}, {theWord:"モテる", retweetCount:0}, {theWord:"名城大", retweetCount:0}, {theWord:"新興国", retweetCount:0}, {theWord:"キキララ", retweetCount:0}, {theWord:"金", retweetCount:0}, {theWord:"旅行会社", retweetCount:0}, {theWord:"メタンハイドレート", retweetCount:0}, {theWord:"井手", retweetCount:0}, {theWord:"マクドナルド", retweetCount:0}, {theWord:"国立科学博物館", retweetCount:0}, {theWord:"バークシャー", retweetCount:0}, {theWord:"成長率", retweetCount:0}, {theWord:"松坂桃李", retweetCount:0}, {theWord:"高齢者", retweetCount:0}, {theWord:"週刊東洋経済", retweetCount:253003}, {theWord:"マイケル・コース", retweetCount:0}, {theWord:"菊地", retweetCount:0}, {theWord:"ドル円", retweetCount:0}, {theWord:"音鼓 -OTOKO-", retweetCount:0}, {theWord:"滋賀", retweetCount:0}, {theWord:"株式市場", retweetCount:0}, {theWord:"資生堂", retweetCount:0}, {theWord:"東野圭吾", retweetCount:0}, {theWord:"投資家", retweetCount:0}, {theWord:"FLYNN", retweetCount:0}, {theWord:"キーエンス", retweetCount:0}, {theWord:"小澤征爾", retweetCount:0}, {theWord:"ダルビッシュ", retweetCount:0}, {theWord:"G1", retweetCount:0}, {theWord:"自動車産業", retweetCount:0}, {theWord:"低インフレ", retweetCount:0}, {theWord:"6月", retweetCount:0}, {theWord:"G2", retweetCount:0}, {theWord:"ワケ", retweetCount:0}, {theWord:"キアヌ・リーヴス", retweetCount:0}, {theWord:"韓国", retweetCount:0}, {theWord:"KIN", retweetCount:0}, {theWord:"欧州", retweetCount:0}, {theWord:"取締役会", retweetCount:0}, {theWord:"国民投票", retweetCount:0}, {theWord:"カリフォルニア", retweetCount:0}, {theWord:"配偶者", retweetCount:0}, {theWord:"AI", retweetCount:0}, {theWord:"特別展", retweetCount:0}, {theWord:"国内政治", retweetCount:0}, {theWord:"傷物語", retweetCount:0}, {theWord:"表現の自由", retweetCount:0}, {theWord:"大西", retweetCount:0}, {theWord:"関東大会", retweetCount:0}, {theWord:"ヘッドマーク", retweetCount:0}, {theWord:"家宅捜索", retweetCount:0}, {theWord:"EU", retweetCount:0}, {theWord:"ウォーターゲート事件", retweetCount:0}, {theWord:"名古屋城", retweetCount:0}, {theWord:"金融政策", retweetCount:0}, {theWord:"ACミラン", retweetCount:0}, {theWord:"インドネシア", retweetCount:0}, {theWord:"イギリス", retweetCount:0}, {theWord:"湘南新宿ライン", retweetCount:0}, {theWord:"消費増税", retweetCount:0}, {theWord:"世論調査", retweetCount:0}, {theWord:"リアル", retweetCount:0}, {theWord:"唯夫", retweetCount:0}, {theWord:"豊", retweetCount:0}, {theWord:"可能性", retweetCount:0}, {theWord:"2015年", retweetCount:0}, {theWord:"欧州諸国", retweetCount:0}, {theWord:"AR", retweetCount:0}, {theWord:"リオ", retweetCount:0}, {theWord:"有罪判決", retweetCount:0}, {theWord:"不動産鑑定士", retweetCount:0}, {theWord:"対象外", retweetCount:0}, {theWord:"エル特急", retweetCount:0}, {theWord:"東京", retweetCount:0}, {theWord:"宅配ピザ", retweetCount:0}, {theWord:"従業員", retweetCount:0}, {theWord:"モスル", retweetCount:0}, {theWord:"札幌2歳S", retweetCount:0}, {theWord:"利用者", retweetCount:0}, {theWord:"関係悪化", retweetCount:0}, {theWord:"LinkedIn", retweetCount:0}, {theWord:"わにとかげぎす", retweetCount:0}, {theWord:"ノアの箱舟", retweetCount:0}, {theWord:"公取委", retweetCount:0}, {theWord:"イタリア", retweetCount:0}, {theWord:"ミャンマー", retweetCount:0}, {theWord:"Oracle", retweetCount:0}, {theWord:"フェンネル", retweetCount:0}, {theWord:"シリコンバレー", retweetCount:0}, {theWord:"保守穏健派", retweetCount:0}, {theWord:"ヨーロッパ", retweetCount:0}, {theWord:"リオ五輪", retweetCount:0}, {theWord:"性同一性障害", retweetCount:0}, {theWord:"国税庁", retweetCount:0}, {theWord:"自民党", retweetCount:0}, {theWord:"長澤まさみ", retweetCount:0}, {theWord:"フリーキック!", retweetCount:0}, {theWord:"江東", retweetCount:0}, {theWord:"証明書", retweetCount:0}, {theWord:"国際エネルギー機関", retweetCount:0}, {theWord:"独", retweetCount:0}, {theWord:"Web", retweetCount:0}, {theWord:"ロハニ", retweetCount:0}, {theWord:"経営者", retweetCount:0}, {theWord:"シャラポワ", retweetCount:0}, {theWord:"喫煙者", retweetCount:0}, {theWord:"自民", retweetCount:0}, {theWord:"清宮", retweetCount:0}, {theWord:"Fess", retweetCount:0}, {theWord:"再生可能エネルギー", retweetCount:0}, {theWord:"回復の兆し", retweetCount:0}, {theWord:"野田稔", retweetCount:0}, {theWord:"依存症", retweetCount:0}, {theWord:"バブル期", retweetCount:0}, {theWord:"評価額", retweetCount:0}, {theWord:"ロッキード", retweetCount:0}, {theWord:"強硬派", retweetCount:0}, {theWord:"ボランチ", retweetCount:0}, {theWord:"下院", retweetCount:0}, {theWord:"サウジアラビア", retweetCount:0}, {theWord:"武装勢力", retweetCount:0}, {theWord:"白岡", retweetCount:0}, {theWord:"May", retweetCount:0}, {theWord:"元夫", retweetCount:0}, {theWord:"ロシア正教会", retweetCount:0}, {theWord:"横浜", retweetCount:0}, {theWord:"ベネズエラ", retweetCount:0}, {theWord:"財務局", retweetCount:0}, {theWord:"ハーバード大", retweetCount:0}, {theWord:"AMO’S STYLE", retweetCount:0}, {theWord:"高城幸司", retweetCount:0}, {theWord:"突然死", retweetCount:0}, {theWord:"無効化", retweetCount:0}, {theWord:"7月", retweetCount:0}, {theWord:"大西英男", retweetCount:0}, {theWord:"大串", retweetCount:0}, {theWord:"東急プラザ", retweetCount:0}, {theWord:"スローフード", retweetCount:0}, {theWord:"眞子さま", retweetCount:0}, {theWord:"東証", retweetCount:0}, {theWord:"キモ", retweetCount:0}, {theWord:"過激派", retweetCount:0}, {theWord:"シンシナティ動物園", retweetCount:0}, {theWord:"フジテレビ", retweetCount:0}} set bList to sortRecListByLabel(aList, "retweetCount", false) of me –昇順ソート –リストに入れたレコードを、指定の属性ラベルの値でソート on sortRecListByLabel(aRecList as list, aLabelStr as string, ascendF as boolean) –ListからNSArrayへの型変換 set aArray to current application’s NSArray’s arrayWithArray:aRecList –ソート set sortDesc to current application’s NSSortDescriptor’s alloc()’s initWithKey:aLabelStr ascending:ascendF set sortDescArray to current application’s NSArray’s arrayWithObjects:sortDesc set sortedArray to aArray’s sortedArrayUsingDescriptors:sortDescArray –NSArrayからListに型変換して返す set bList to (sortedArray) as list return bList end sortRecListByLabel |
asoc_レコード内の計算(平均)v2
AppleScript名:asoc_レコード内の計算(平均)v2 |
— Created 2014-11-19 by Takaaki Naganoya — 2014 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aCompanyRec to {employees:{{age:20, nameStr:"A"}, {age:23, nameStr:"B"}, {age:19, nameStr:"C"}}} set aDic to current application’s NSDictionary’s dictionaryWithDictionary:aCompanyRec set aveAge to (aDic’s valueForKeyPath:"employees.@avg.age") set aveAgeNum to aveAge as real –> 20.666666666667 |
asoc_レコード内の計算(カウント)v2
AppleScript名:asoc_レコード内の計算(カウント)v2 |
— Created 2014-11-19 by Takaaki Naganoya — 2014 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aCompanyRec to {employees:{{age:20, nameStr:"A"}, {age:23, nameStr:"B"}, {age:19, nameStr:"C"}}} set aDic to current application’s NSDictionary’s dictionaryWithDictionary:aCompanyRec set aveAge to (aDic’s valueForKeyPath:"employees.@count.age") set aveAgeNum to aveAge as real –> 3.0 |
asoc_レコード内の計算(最大)v2
AppleScript名:asoc_レコード内の計算(最大)v2 |
— Created 2014-11-19 by Takaaki Naganoya — 2014 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aCompanyRec to {employees:{{age:20, nameStr:"A"}, {age:23, nameStr:"B"}, {age:19, nameStr:"C"}}} set aDic to current application’s NSDictionary’s dictionaryWithDictionary:aCompanyRec set aveAge to (aDic’s valueForKeyPath:"employees.@max.age") set aveAgeNum to aveAge as real –> 23.0 |
asoc_レコード内の計算(最小)v2
AppleScript名:asoc_レコード内の計算(最小)v2 |
— Created 2014-11-19 by Takaaki Naganoya — 2014 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aCompanyRec to {employees:{{age:20, nameStr:"A"}, {age:23, nameStr:"B"}, {age:19, nameStr:"C"}}} set aDic to current application’s NSDictionary’s dictionaryWithDictionary:aCompanyRec set aveAge to (aDic’s valueForKeyPath:"employees.@min.age") set aveAgeNum to aveAge as real –> 19.0 |
asoc_レコード内の計算(合計)v2
AppleScript名:asoc_レコード内の計算(合計)v2 |
— Created 2014-11-19 by Takaaki Naganoya — 2014 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aCompanyRec to {employees:{{age:20, nameStr:"A"}, {age:23, nameStr:"B"}, {age:19, nameStr:"C"}}} set aDic to current application’s NSDictionary’s dictionaryWithDictionary:aCompanyRec set aveAge to (aDic’s valueForKeyPath:"employees.@sum.age") set aveAgeNum to aveAge as real –> 62.0 |
指定リストの次元を取得する v3
任意のリスト(配列)変数の次元を取得するAppleScriptです。
手軽に多次元配列を宣言してアクセスできるAppleScriptですが、作成した配列変数の次元を確認する方法は用意されていません。
そこで、指定リスト(配列)の次元数を取得するものを書いてみました。
日常的に2次元配列とか3次元配列は使いますが、4次元配列まではあまり使ったことがありません。実用上は3次元配列ぐらいでしょうか。
たまに2次元配列が使えない言語とか、実用上は2次元配列ぐらいまでしか直接宣言できない言語があって驚かされます。
AppleScript名:指定リストの次元を取得する v3 |
use AppleScript version "2.4" use scripting additions set aList to {{1, 2, 3}, {4, 5, 6}} –2D List set aDim to getDimension given tArray:aList –> 2 set bList to {{{1, 2}, {2, 3}, {3, 4}}, {{1, 2}, {2, 3}, {3, 4}}, {{1, 2}, {2, 3}, {3, 4}}} –3D List set bDim to getDimension given tArray:bList –> 3 set cList to {1, 2, 3, 4, 5, 6} –1D List set cDim to getDimension given tArray:cList –> 1 set dList to {{{{1, 2}, {2, 3}}, {{1, 2}, {2, 3}}, {{1, 2}, {2, 3}}}} –4D List set dDim to getDimension given tArray:dList –> 4 –指定Listの次元を再帰で取得する on getDimension given tArray:aList as list : {}, curDim:aNum as integer : 1 set anItem to contents of first item of aList set aClass to class of anItem if aClass = list then set aNum to aNum + 1 set aRes to getDimension given tArray:anItem, curDim:aNum else return aNum end if end getDimension |
2D Listをユニーク化
AppleScript名:2D Listをユニーク化(asoc) |
— Created 2017-05-25 23:27:42 +0900 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aList to {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {64620, 537, 32893}, {64620, 537, 32893}, {64620, 537, 32893}, {64620, 537, 32893}} set bList to uniquifyList(aList) of me –> {{0, 0, 0}, {64620, 537, 32893}} on uniquifyList(aList as list) set aArray to current application’s NSArray’s arrayWithArray:aList set bArray to aArray’s valueForKeyPath:"@distinctUnionOfObjects.self" return bArray as list end uniquifyList |
1D Listをユニーク化 v2
AppleScript名:1D Listをユニーク化 v2 |
— Created 2014-11-25 by Takaaki Naganoya — 2014 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" –set aList to {{aName:"Apple", aNum:1}, {aName:"Orange", aNum:1}, {aName:"Apple", aNum:1}} set aList to {1, 1, 1, 3} set aRes to uniquify1DList(aList, true) –> {1, 10, 90, 100, 300} –1D/2D Listをユニーク化 on uniquify1DList(theList as list, aBool as boolean) set aArray to current application’s NSArray’s arrayWithArray:theList set bArray to aArray’s valueForKeyPath:"@distinctUnionOfObjects.self" if aBool = true then return bArray as list else return bArray end if end uniquify1DList |
listの項目をフィルタリング(項目文字長)
AppleScript名:listの項目をフィルタリング(項目文字長) |
— Created 2014-11-21 by Takaaki Naganoya — 2014 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aList to {"piyomaru", "Piyomaru Software", "Naganoya", "Takaaki", "MacBook Pro Retina mid 2012"} set bList to filterListUsingPredicate(aList, "length > 8") –文字列長が8文字より長い項目を返す –> {"MacBook Pro Retina mid 2012", "Piyomaru Software"} set cList to filterListUsingPredicate(aList, "SELF MATCHES ’.*e$’") –正規表現で末尾が"e" –> {"Piyomaru Software"} set dList to filterListUsingPredicate(aList, "SELF LIKE ’piyo*’") –> {"piyomaru"} set eList to filterListUsingPredicate(aList, "SELF LIKE[c] ’piyo*’") –> {"piyomaru", "Piyomaru Software"} set fList to filterListUsingPredicate(aList, "SELF CONTAINS[c] ’Piyo’") –> {"piyomaru", "Piyomaru Software"} on filterListUsingPredicate(aList as list, aPredicateStr as string) –ListからNSArrayへの型変換 set setKey to current application’s NSMutableSet’s setWithArray:aList –抽出 set aPredicate to current application’s NSPredicate’s predicateWithFormat:aPredicateStr set aRes to (setKey’s filteredSetUsingPredicate:aPredicate) set bRes to aRes’s allObjects() –NSArrayからListに型変換して返す set cRes to bRes as {list, list of string or string} return cRes end filterListUsingPredicate |
listの項目をフィルタリング(キーワードを含む)
AppleScript名:listの項目をフィルタリング(キーワードを含む) |
— Created 2014-11-21 by Takaaki Naganoya — 2014 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "ASObjCExtras" set aList to {"piyomaru", "Naganoya", "Takaaki", "MacBook Pro Retina mid 2012", "piyomarusoft"} set bList to filterListUsingPredicate(aList, "SELF contains[cd] %@", "Piyo") –部分一致 –> {"piyomaru", "piyomarusoft"} set cList to filterListUsingPredicate(aList, "SELF matches[cd] %@", "piyomaru") –完全一致 –> {"piyomaru"} set dList to filterListUsingPredicate(aList, "SELF like[c] %@", "*soft") –後方一致 –> {"piyomarusoft"} on filterListUsingPredicate(aList as list, aPredicateStr as string, targStr as string) set setKey to current application’s NSMutableSet’s setWithArray:aList set aPredicate to current application’s NSPredicate’s predicateWithFormat_(aPredicateStr, targStr) set aRes to (setKey’s filteredSetUsingPredicate:aPredicate) set bRes to aRes’s allObjects() set cRes to bRes as {list, list of string or string} return cRes end filterListUsingPredicate –2Dリストから、指定インデックスアイテムで、指定データが該当する最初のものを返す on searchInListByIndexItem(aList as list, itemNum as integer, hitData as string) –ListからNSMutableSetへの型変換 set setKey to current application’s NSMutableSet’s setWithArray:aList –Predicate Stringを組み立てる if itemNum < 1 then return {} set aPredicateStr to ("SELF[" & (itemNum – 1) as string) & "] == ’" & hitData & "’" –抽出 set aPredicate to current application’s NSPredicate’s predicateWithFormat:aPredicateStr set aRes to (setKey’s filteredSetUsingPredicate:aPredicate) set bRes to aRes’s allObjects() –NSArrayからListに型変換して返す set cRes to bRes as list if cRes is not equal to {} then set cRes to contents of first item of cRes end if return cRes end searchInListByIndexItem |