Sindre Sorhusによる、SOMLのAppleScriptライブラリ「SOML」がオープンソースで公開され、サンプルAppleScriptも公開されたものの、それだけでは動作内容がわからなかったので、ひととおりのデータ型でエンコード/デコードを試してみました。
SOMLはJSONのような可読性の高いデータ記述形式であり、データの保持や読み込みのひとつの方向性を示すものです。
| AppleScript名:SOML_encode_decode_samples 1.scpt |
| — – Created by: Takaaki Naganoya – Created on: 2026/11/17 — – Copyright © 2026 Piyomaru Software, All Rights Reserved — use AppleScript use framework "Foundation" use scripting additions use somlLib : script "SOML" –Encode & Decode Integer set aRec to {aLabel:1} set aRes to encode(aRec) of somlLib (* "aLabel: 1 " *) set bRes to decode(aRes) of somlLib –> {aLabel:1} log aRec is equal to bRes –Encode & Decode Real set aRec to {aLabel:1.0} set aRes to encode(aRec) of somlLib (* "aLabel: 1.0 " *) set bRes to decode(aRes) of somlLib –> {aLabel:1.0} log aRec is equal to bRes –Encode & Decode String set aRec to {aLabel:"1"} set aRes to encode(aRec) of somlLib (* "aLabel: ’1’ " *) set bRes to decode(aRes) of somlLib –> {aLabel:"1"} log aRec is equal to bRes –Encode & Decode Integer Array set aRec to {aLabel:{1, 2, 3}} set aRes to encode(aRec) of somlLib (* "aLabel: [ 1 2 3 ] " *) set bRes to decode(aRes) of somlLib –> {aLabel:{1, 2, 3}} log aRec is equal to bRes –Encode & Decode String Array set aRec to {aLabel:{"1", "2", "3"}} set aRes to encode(aRec) of somlLib (* "aLabel: [ ’1’ ’2’ ’3’ ] " *) set bRes to decode(aRes) of somlLib –> {aLabel:{"1", "2", "3"}} log aRec is equal to bRes –Encode & Decode Record set aRec to {aLabel:{aaa:"1", bbb:"2", ccc:"3"}} set aRes to encode(aRec) of somlLib (* "aLabel: { aaa: ’1’ bbb: ’2’ ccc: ’3’ } " *) set bRes to decode(aRes) of somlLib –> {aLabel:{aaa:"1", bbb:"2", ccc:"3"}} log aRec is equal to bRes –Encode & Decode Record (Integer array) set aRec to {aLabel:{aaa:{1, 2, 3}, bbb:{2, 3, 4}, ccc:{5, 6, 7}}} set aRes to encode(aRec) of somlLib (* "aLabel: { aaa: [ 1 2 3 ] bbb: [ 2 3 4 ] ccc: [ 5 6 7 ] } " *) set bRes to decode(aRes) of somlLib –> {aLabel:{aaa:{1, 2, 3}, bbb:{2, 3, 4}, ccc:{5, 6, 7}}} log aRec is equal to bRes –Encode & Decode Record (String array) set aRec to {aLabel:{aaa:{"1", "2", "3"}, bbb:{"2", "3", "4"}, ccc:{"5", "6", "7"}}} set aRes to encode(aRec) of somlLib (* "aLabel: { aaa: [ ’1’ ’2’ ’3’ ] bbb: [ ’2’ ’3’ ’4’ ] ccc: [ ’5’ ’6’ ’7’ ] } " *) set bRes to decode(aRes) of somlLib –> {aLabel:{aaa:{"1", "2", "3"}, bbb:{"2", "3", "4"}, ccc:{"5", "6", "7"}}} log aRec is equal to bRes –Encode & Decode Record (With whitespace label) set aRec to {|a Label|:{|aaa aaa|:{"1", "2", "3"}}} set aRes to encode(aRec) of somlLib (* "’a Label’: { ’aaa aaa’: [ ’1’ ’2’ ’3’ ] } " *) set bRes to decode(aRes) of somlLib –> {|a label|:{|aaa aaa|:{"1", "2", "3"}}} log aRec is equal to bRes –Encode & Decode Record (With Japanese Character label) set aRec to {|ラベル|:{|日本語ラベル|:{"あ", "い", "う"}}} set aRes to encode(aRec) of somlLib (* "’ラベル’: { ’日本語ラベル’: [ ’あ’ ’い’ ’う’ ] } " *) set bRes to decode(aRes) of somlLib –> {|ラベル|:{|日本語ラベル|:{"あ", "い", "う"}}} log aRec is equal to bRes |
(Visited 1 times, 1 visits today)
