AppleScript名:recordをXMLに v2 |
use AppleScript version "2.4" use scripting additions use framework "Foundation" set theRecord to {firstName:"Saga", lastName:"Norén", city:"Malmö"} makeXMLDocWithRecord(theRecord) –> (* "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<character>\n <firstName>Saga</firstName>\n <city>Malmö</city>\n <lastName>Norén</lastName>\n</character>" *) set theRecord to {firstName:"Saga", lastName:"Norén", city:"Malmö", partner:{firstName:"Martin", lastName:"Rohde", city:"København"}} makeXMLDocWithRecord(theRecord) –> (* "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<character>\n <firstName>Saga</firstName>\n <lastName>Norén</lastName>\n <city>Malmö</city>\n <partner>\n <firstName>Martin</firstName>\n <city>København</city>\n <lastName>Rohde</lastName>\n </partner>\n</character>" *) –Record –> XML (text) on makeXMLDocWithRecord(theRecord) — make root element set rootElement to current application’s NSXMLNode’s elementWithName:"character" — make XML document set theXMLDocument to current application’s NSXMLDocument’s alloc()’s initWithRootElement:rootElement theXMLDocument’s setDocumentContentKind:(current application’s NSXMLDocumentXMLKind) theXMLDocument’s setStandalone:true theXMLDocument’s setCharacterEncoding:"UTF-8" — make dictionary from record set anNSDictionary to current application’s NSDictionary’s dictionaryWithDictionary:theRecord — add children to root element its addChildTo:rootElement withDictionary:anNSDictionary — return as string with whatever formatting options you want return (theXMLDocument’s XMLStringWithOptions:(current application’s NSXMLNodePrettyPrint)) as text end makeXMLDocWithRecord on addChildTo:parentElement withDictionary:theDict set theKeys to theDict’s allKeys() as list repeat with i from 1 to count of theKeys set theKey to item i of theKeys set theValue to (theDict’s objectForKey:theKey) set newElement to (current application’s NSXMLNode’s elementWithName:theKey) (parentElement’s addChild:newElement) if (theValue’s isKindOfClass:(current application’s NSDictionary)) as boolean then (its addChildTo:newElement withDictionary:theValue) else (newElement’s setObjectValue:theValue) end if end repeat end addChildTo:withDictionary: |
タグ: 10.13savvy
XmlToDictKitでXMLをDictionaryに(remote file)
AppleScript名:XmlToDictKitでXMLをDictionaryに(remote file) |
— Created 2016-11-05 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "XmlToDictKit" –https://github.com/nicklockwood/XMLDictionary set aURL to current application’s |NSURL|’s alloc()’s initWithString:"http://www.ibiblio.org/xml/examples/shakespeare/all_well.xml" set xmlString to current application’s NSString’s alloc()’s initWithContentsOfURL:aURL encoding:(current application’s NSUTF8StringEncoding) |error|:(missing value) if xmlString = missing value then return false set xmlDoc to (current application’s NSDictionary’s dictionaryWithXMLString:xmlString) as record |
XmlToDictKitでXMLをDictionaryに(local file)
AppleScript名:XmlToDictKitでXMLをDictionaryに(local file) |
— Created 2016-11-05 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "XmlToDictKit" –https://github.com/nicklockwood/XMLDictionary set aFile to POSIX path of (choose file) set aURL to current application’s |NSURL|’s fileURLWithPath:aFile set xmlString to current application’s NSString’s alloc()’s initWithContentsOfURL:aURL encoding:(current application’s NSUTF8StringEncoding) |error|:(missing value) if xmlString = missing value then return false set xmlDoc to (current application’s NSDictionary’s dictionaryWithXMLString:xmlString) as record |
XMLをrecordにv2
XMLを解釈してAppleScriptのレコード型のデータに変換するAppleScriptです。
ひとことにXMLといっても、割と書き方にばらつきがあり、1つのルーチンやライブラリで解決できるというものでもない、ということを日々痛感しています。
さまざまな処理方法をおこなうXML解釈プログラムを用意しておいて、かたっぱしから試して適合するものを使っているというところです。本ルーチンで処理できる(解釈しやすい結果を出せる)XMLもあれば、そうでないものもあることでしょう。
また、解釈したXMLのタグについてもそのままではAppleScriptで取り扱えない(スペースを含むとか、特殊文字を含むとか)ものもあり、
XML → NSDictionary → Record
と、AppleScriptのRecordまで変換してしまうと逆に取り扱いにくい場合もあるため、
XML → NSDictionary
と、とどめておいて適宜NSDictionaryからデータを取り出すような処理を行うこともあります。
AppleScript名:XMLをrecordにv2 |
–2015 Shane Stanley & Alex Zavatone — Modified 2016-11-06 by Takaaki Naganoya use AppleScript version "2.4" use scripting additions use framework "Foundation" property dictStack : missing value — stack to hold array of dictionaries property textInProgress : "" — string to collect text as it is found property anError : missing value — if we get an error, store it here set xmlRes to my makeRecordWithXML:(returnData() of me) –> {|character|:{firstName:{|contents|:"Saga"}, lastName:{|contents|:"Norén"}, city:{|contents|:"Malmö"}, partner:{firstName:{|contents|:"Martin"}, lastName:{|contents|:"Rohde"}, city:{|contents|:"København"}, attributes:{approach:"dogged"}}}} on makeRecordWithXML:xmlString — set up properties set my dictStack to current application’s NSMutableArray’s array() — empty mutable array set anEmpty to current application’s NSMutableDictionary’s |dictionary|() (my dictStack)’s addObject:anEmpty — add empty mutable dictionary set my textInProgress to current application’s NSMutableString’s |string|() — empty mutable string — convert XML from string to data set anNSString to current application’s NSString’s stringWithString:xmlString set theData to anNSString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding) — initialize an XML parser with the data set theNSXMLParser to current application’s NSXMLParser’s alloc()’s initWithData:theData — set this script to be the parser’s delegate theNSXMLParser’s setDelegate:me — tell it to parse the XML set theResult to theNSXMLParser’s parse() if theResult then — went OK, get first item on stack return ((my dictStack)’s firstObject()) –as record else — error, so return error error (my anError’s localizedDescription() as text) end if end makeRecordWithXML: — this is an XML parser delegate method. Called when new element found on parser:anNSXMLParser didStartElement:elementName namespaceURI:aString qualifiedName:qName attributes:aRecord — store reference to last item on the stack set parentDict to my dictStack’s lastObject() — make new child set childDict to current application’s NSMutableDictionary’s |dictionary|() — if there are attributes, add them as a record with key "attributes" if aRecord’s |count|() > 0 then childDict’s setValue:aRecord forKey:"attributes" end if — see if there’s already an item for this key set existingValue to parentDict’s objectForKey:elementName if existingValue is not missing value then — there is, so if it’s an array, store it… if (existingValue’s isKindOfClass:(current application’s NSMutableArray)) as boolean then set theArray to existingValue else — otherwise create an array and add it set theArray to current application’s NSMutableArray’s arrayWithObject:existingValue parentDict’s setObject:theArray forKey:elementName end if — then add the new dictionary to the array theArray’s addObject:childDict else — add new dictionary directly to the parent parentDict’s setObject:childDict forKey:elementName end if — also add the new dictionary to the end of the stack (my dictStack)’s addObject:childDict end parser:didStartElement:namespaceURI:qualifiedName:attributes: — this is an XML parser delegate method. Called at the end of an element on parser:anNSXMLParser didEndElement:elementName namespaceURI:aString qualifiedName:qName — if any text has been stored, add it as a record with key "contents" if my textInProgress’s |length|() > 0 then set dictInProgress to my dictStack’s lastObject() dictInProgress’s setObject:textInProgress forKey:"contents" — reset textInProgress property for next element set my textInProgress to current application’s NSMutableString’s |string|() end if — remove last item from the stack my dictStack’s removeLastObject() end parser:didEndElement:namespaceURI:qualifiedName: — this is an XML parser delegate method. Called when string is found. May be called repeatedly on parser:anNSXMLParser foundCharacters:aString — only append string if it’s not solely made of space characters (which should be, but aren’t, caught by another delegate method) if (aString’s stringByTrimmingCharactersInSet:(current application’s NSCharacterSet’s whitespaceAndNewlineCharacterSet()))’s |length|() > 0 then (my textInProgress)’s appendString:aString end if end parser:foundCharacters: — this is an XML parser delegate method. Called when there’s an error on parser:anNSXMLParser parseErrorOccurred:anNSError set my anError to anNSError end parser:parseErrorOccurred: on returnData() return "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <rss version=\"2.0\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:dcndl=\"http://ndl.go.jp/dcndl/terms/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:dcmitype=\"http://purl.org/dc/dcmitype/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:openSearch=\"http://a9.com/-/spec/opensearchrss/1.0/\" xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"> <channel> <title>Mac使いへの道 – 国立国会図書館サーチ OpenSearch</title> <link>http://iss.ndl.go.jp/api/opensearch?title=Mac%E4%BD%BF%E3%81%84%E3%81%B8%E3%81%AE%E9%81%93</link> <description>Search results for title=Mac使いへの道 </description> <language>ja</language> <openSearch:totalResults>1</openSearch:totalResults> <openSearch:startIndex>1</openSearch:startIndex> <openSearch:itemsPerPage></openSearch:itemsPerPage> <item> <title>Mac使いへの道</title> <link>http://iss.ndl.go.jp/books/R100000002-I000003026578-00</link> <description> <![CDATA[<p>ソフトバンクパブリッシング,4797316489</p> <ul><li>タイトル: Mac使いへの道</li> <li>タイトル(読み): Macツカイ エノ ミチ</li> <li>責任表示: 長野谷隆昌 著,</li> <li>NDC(9): 548.29</li> </ul>]]> </description> <author>長野谷隆昌 著,</author> <category>本</category> <guid isPermaLink=\"true\">http://iss.ndl.go.jp/books/R100000002-I000003026578-00</guid> <pubDate>Thu, 08 May 2003 09:00:00 +0900</pubDate> <dc:title>Mac使いへの道</dc:title> <dcndl:titleTranscription>Macツカイ エノ ミチ</dcndl:titleTranscription> <dc:creator>長野谷隆昌 著</dc:creator> <dc:publisher>ソフトバンクパブリッシング</dc:publisher> <dcterms:issued xsi:type=\"dcterms:W3CDTF\">2001</dcterms:issued> <dc:identifier xsi:type=\"dcndl:ISBN\">4797316489</dc:identifier> <dc:identifier xsi:type=\"dcndl:JPNO\">20206272</dc:identifier> <dc:subject>コンピュータ</dc:subject> <dc:subject xsi:type=\"dcndl:NDLC\">M154</dc:subject> <dc:subject xsi:type=\"dcndl:NDC9\">548.29</dc:subject> <dcterms:description>文献あり</dcterms:description> <rdfs:seeAlso rdf:resource=\"http://id.ndl.go.jp/bib/000003026578\"/> </item> </channel> </rss>" end returnData |
PKXMLKitでRSSをrecordに
AppleScript名:PKXMLKitでRSSをrecordに |
— Created 2017-12-18 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "PKXMLKit" –https://github.com/pawankv89/PKXMLParser set aURL to "http://piyocast.com/as/feed/" set aXMLURL to current application’s |NSURL|’s URLWithString:aURL set xmlString to current application’s NSString’s alloc()’s initWithContentsOfURL:aXMLURL encoding:(current application’s NSUTF8StringEncoding) |error|:(missing value) set xmlDoc to current application’s NSDictionary’s dictionaryWithXMLString:xmlString set titleList to (xmlDoc’s valueForKeyPath:"channel.item.title") as list –> {"アドウェア「OSX.Pirrit」のAppleScriptコードを読んでみた", "表示中のCotEditor書類の「次」のファイルを縦書きでオープン", "ハンドラ間接呼び出し", …} |
recordをJSON文字列に
recordをJSON文字列に変換するAppleScriptです。
AppleScript名:recordをJSON文字列に.scpt |
— Created 2015-07-20 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aRec to {abc:"test", bcd:"test2", cde:"test3"} set aJson to convRecToJson(aRec) of me as string –> "{"abc":"test","bcd":"test2","cde":"test3"}" on convRecToJson(aRec) set aDict to current application’s NSDictionary’s dictionaryWithDictionary:aRec set jsonData to current application’s NSJSONSerialization’s dataWithJSONObject:aDict options:(0 as integer) |error|:(missing value) –0 is NSJSONWritingPrettyPrinted set resString to current application’s NSString’s alloc()’s initWithData:jsonData encoding:(current application’s NSUTF8StringEncoding) return resString end convRecToJson |
ASOCでjson文字列をrecordに
AppleScript名:ASOCでjson文字列をrecordに |
— Created 2015-07-20 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set jsonText to "{\"abc\":\"test\",\"bcd\":\"test2\",\"cde\":\"test3\"}" set jsonString to current application’s NSString’s stringWithString:jsonText –> (NSString) "{"abc":"test","bcd":"test2","cde":"test3"}" set jsonData to jsonString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding) –> (NSData) <7b226162 63223a22 74657374 222c2262 6364223a 22746573 7432222c 22636465 223a2274 65737433 227d> set aJsonDict to current application’s NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value) –> (NSDictionary) {abc:"test", bcd:"test2", cde:"test3"} set aRec to aJsonDict as record –> {abc:"test", bcd:"test2", cde:"test3"} |
NSDictionaryを値とキーの列挙で作成する 2
AppleScript名:NSDictionaryを値とキーの列挙で作成する 2 |
— Created 2017-03-03 01:16:41 +0900 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set bundleList to {"com.apple.filemerge", "com.barebones.bbedit", "com.barebones.textwrangler"} set dummyList to {"fdummy", "bbedummy", "twdummy"} set aDict to current application’s NSMutableDictionary’s dictionaryWithObjects:dummyList forKeys:bundleList –> (NSDictionary) {com.apple.filemerge:"fdummy", com.barebones.textwrangler:"twdummy", com.barebones.bbedit:"bbedummy"} set aRes to aDict’s valueForKey:"com.barebones.bbedit" –> (NSString) "bbedummy" |
asoc_レコードをリストから生成
AppleScript名:asoc_レコードをリストから生成 |
use AppleScript version "2.4" use scripting additions use framework "Foundation" set labelList to {"Address", "Names"} set valueList to {"ここらへん", "ぴよまるさん"} set theResult to current application’s NSDictionary’s dictionaryWithObjects:(valueList) forKeys:(labelList) set aRec to theResult as record –> {Address:"ここらへん", Names:"ぴよまるさん"} |
ASOCでNSPredicateによる正規表現を併用した抽出
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 |
リストに入れたレコードを、指定の属性ラベルの値で抽出
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 |