Sindre Sorhusによる、SOMLのAppleScriptライブラリ「SOML」がオープンソースで公開されました。
SOMLは設定ファイルなどを保存するさいに、XMLのタグの煩雑さを一部省略したplist、さらにタグを簡略化したJSONがあり、そこからさらに簡略化したのがSOMLやYAMLだとSOMLのライブラリ説明ページに書かれています。
SOMLの記法は以下のようなものです。
name: 'api-gateway' port: 8080 # The load balancer expects this port. timeout: 30s launch-date: 2027-09-19 windows-path: 'C:\Users\sindre\dev' description: ''' Terminates TLS. Routes requests to internal services. ''' allowed-origins: [ 'https://example.com' 'https://example.org' ]
タグというよりも、インデントで階層構造を記述したようなかっこうです。
AppleScriptで設定値を書き込むには、ながらくAppleScript自身のproperty宣言を自身で書き換えることで行われてきました。
しかし、セキュリティ上の都合によりこうした運用は、とくにアプレット形式での自己書き換えは禁止されるようになりました。
plist形式を利用することで、設定値の保存は行えますが、アプリケーションのオブジェクトやAppleScriptオブジェクトは書き込めません(文字列化すれば無理ではありませんが)。
JSONやSOMLもそうしたplistに近い仕様であるため、AppleScript関連やアプリケーションオブジェクトのデータをそのまま保存することはできませんが、JSONが広く使われるようになり、OS側にも認知されるようになったのと同様、SOMLも同じような扱いになるかもしれません。
SOML用のAppleScriptライブラリについていたサンプルScriptを確認してみました。ただ、いろいろ書き換えないとユーザー環境では動かないうえに、AppleScriptの流儀とは異なっていました。
ライブラリ自体には割と豊富な機能がそろっているようなのですが、サンプルScriptが動かしにくいので、そのままでは利用されずにもったいないので「常識的にはこのぐらいサンプルがないと使いにくい」という不便を解消するためにいろいろ書いてみました。
以下のAppleScriptはAppleScriptライブラリ「SOML」のインストールを必要とします。
| AppleScript名:sample script 1.scpt |
| — – Created by: Takaaki Naganoya – Created on: 2026/11/17 — – Copyright © 2026 Piyomaru Software, All Rights Reserved — use AppleScript version "2.8" use scripting additions use soml : script "SOML" set aPOSIXPath to POSIX path of (choose file) set config to soml’s decodeFile(aPOSIXPath) set n1Res to |name| of config –=> "api-gateway" set n2Res to |port| of server of config –=> 8080 set n3Res to |host| of item 2 of servers of config –=> "b.internal" set n4Res to |socket.io| of deps of config –=> "^4" set n5Res to soml’s toSeconds(|timeout| of config) –=> 90.0 return {n1Res, n2Res, n3Res, n4Res, n5Res} –> {"api-gateway", 8080, "b.internal", "^4", 90.0} |
| AppleScript名:sample script 2.scpt |
| — – Created by: Takaaki Naganoya – Created on: 2026/11/17 — – Copyright © 2026 Piyomaru Software, All Rights Reserved — use AppleScript version "2.8" use scripting additions use soml : script "SOML" set config to {|name|:"api-gateway", replicas:3, |timeout|:{class:SOML duration, value:"1m30s"}, |launch-date|:{class:SOML date, value:"2027-09-19"}, server:{|host|:"localhost", |port|:8080}, servers:{{|host|:"a.internal"}, {|host|:"b.internal"}}, deps:{|socket.io|:"^4"}} set n1Res to |name| of config –=> "api-gateway" set n2Res to |port| of server of config –=> 8080 set n3Res to |host| of item 2 of servers of config –=> "b.internal" set n4Res to |socket.io| of deps of config –=> "^4" set n5Res to soml’s toSeconds(|timeout| of config) –=> 90.0 return {n1Res, n2Res, n3Res, n4Res, n5Res} –> {"api-gateway", 8080, "b.internal", "^4", 90.0} |
| AppleScript名:sample script 3.scpt |
| — – Created by: Takaaki Naganoya – Created on: 2026/11/17 — – Copyright © 2026 Piyomaru Software, All Rights Reserved — use AppleScript version "2.8" use scripting additions use somlLib : script "SOML" set configStr to "# config.soml name: ’api-gateway’ replicas: 3 timeout: 1m30s launch-date: 2027-09-19 server: { host: ’localhost’ port: 8080 } servers: [ {host: ’a.internal’} {host: ’b.internal’} ] deps: {’socket.io’: ’^4’} " set config to decode(configStr) of somlLib set n1Res to |name| of config –=> "api-gateway" set n2Res to |port| of server of config –=> 8080 set n3Res to |host| of item 2 of servers of config –=> "b.internal" set n4Res to |socket.io| of deps of config –=> "^4" set n5Res to somlLib’s toSeconds(|timeout| of config) –=> 90.0 return {n1Res, n2Res, n3Res, n4Res, n5Res} –> {"api-gateway", 8080, "b.internal", "^4", 90.0} |
