record in listをCSV書き出しのために、ルール指定listの内容にのっとって、list in list(2D list)に変換するAppleScriptです。
とくに、ルール指定listの中にはrecordのラベルを指定しておくのですが、ヌル項目を出力するために、ルール中に””を指定しておくと、””を2D List中に出力するようになっています。
recordから任意のラベルの値を取り出すのにrun scriptを使ってevalのような動作を行なっています。これが処理速度上のボトルネックになるかどうか。もしも、ボトルネックになるようなら、NSRecordに変換したのちにValueForKey:で取り出してもよいでしょう。
ただ、ほとんどの場合にCocoa Objectを使ったほうが遅くなると思います(データが小さすぎるケースがほとんどなので)。
| AppleScript名:結合順をラベルのリストで指定し、record in listをlist in listに書き換える(CSV書き出し用下処理).scpt |
| — – Created by: Takaaki Naganoya – Created on: 2026/11/02 – Copyright © 2026 Piyomaru Software, All Rights Reserved — set aData to {{aaa:"01", bbb:"02", ccc:"03"}, {aaa:"11", bbb:"12", ccc:"13"}} set aRule to {"", "ccc", "bbb", "aaa", ""} set aRes to getValueFieldWithRule(aData, aRule) of me –> {{"", "03", "02", "01", ""}, {"", "13", "12", "11", ""}} set bRule to {"", "aaa", "bbb", "ccc", ""} set bData to {{aaa:1, bbb:2, ccc:3}, {aaa:11, bbb:12, ccc:13}} set bRes to getValueFieldWithRule(bData, bRule) of me –> {{"", 1, 2, 3, ""}, {"", 11, 12, 13, ""}} –結合順をラベルのリストで指定し、record in listをlist in listに書き換える(CSV書き出し用下処理) on getValueFieldWithRule(aData, aRule) script spd property aData : {} property aResult : {} property aRow : {} end script set (aData of spd) to aData set (aResult of spd) to {} repeat with aRecord in (aData of spd) set (aRow of spd) to {} –1行分のデータ repeat with oneLabel in aRule set aLabel to contents of oneLabel if aLabel is not equal to "" then set aScript to "on run {aRecord}" & linefeed & "return " & aLabel & " of aRecord" & linefeed & "end run" set aValue to run script aScript with parameters {contents of aRecord} else set aValue to "" –空きフィールドの出力 end if set end of (aRow of spd) to aValue end repeat set end of (aResult of spd) to (aRow of spd) end repeat return (aResult of spd) end getValueFieldWithRule |
(Visited 1 times, 1 visits today)
