plutil -typeは、plist(property list)ファイルの指定したキーパスの値がどの型かを表示する。
値の型を確認する
-type <keypath>の形式で指定する。
$ plutil -type Name sample.plist
string
$ plutil -type Count sample.plist
integer
$ plutil -type Tags sample.plist
array
型はstring/integer/float/bool/date/data/array/dictionaryのいずれかで表示される。
-expectで期待する型かを検証する
-expect <expect_type>を併用すると、値の型が期待通りであるかを検証できる。一致すれば型名を表示して終了コード0、不一致であればエラーメッセージと共に終了コード1になる。
$ plutil -type Name -expect string sample.plist
string
$ echo $?
0
$ plutil -type Name -expect integer sample.plist
sample.plist: Value at [Name] expected to be integer but is string
$ echo $?
1
外部から受け取ったplistファイルを処理する前に、想定した型のキーが揃っているかをスクリプトで事前検証したい場合に使える。-extractの-expectは値そのものを取り出しつつ型検証するのに対し、-typeは型の確認だけを行いたい場合に使う。
参考
【plutil】-extractでplistから値を抽出する\第一線のプログラマーの行動原理を学べる!/
