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 |
More from my site
(Visited 17 times, 1 visits today)