はじめに
サービスというか、json
作って、script
を置いただけですが、一応、以下のコマンドで調べられるようにしました。
jqコマンドを利用した検索
$ curl -sL syui.github.io/script/macbook-model-command.sh | sh
元データであるjsonの出力
$ curl -s https://raw.githubusercontent.com/syui/json-script/master/json/macbook-model.json
追記:
jq依存を解消しました。
作った理由
MacBookの年式を調べるコマンドがないような気がした
system_profiler
で年式を調べられないのかと思ったのですが、よく分かりませんでした。Webに当たると、機種IDに対応したモデルにて年式が公式ページより書かれているみたいでしたので、それを参照するコマンドを作りました。
$ curl -s http://support.apple.com/kb/{HT1635,HT4132,HT3255} | sed -n '/<tbody/,/<\/tbody>/p' | grep -B 2 `system_profiler SPHardwareDataType | grep "Model Iden" |tr -d ' ' | cut -d : -f 2` | tr -d '\t' | sed -e 's/<[^>]*>//g' -e '/^$/d'
# test:MacBookPro11,1
$ curl -s http://support.apple.com/kb/{HT1635,HT4132,HT3255} | sed -n '/<tbody/,/<\/tbody>/p' | grep -B 2 "MacBookPro11,1" | tr -d '\t' | sed -e 's/<[^>]*>//g' -e '/^$/d'
# test:MacBook7,1
$ curl -s http://support.apple.com/kb/{HT1635,HT4132,HT3255} | sed -n '/<tbody/,/<\/tbody>/p' | grep -B 2 "MacBook7,1" | tr -d '\t' | sed -e 's/<[^>]*>//g' -e '/^$/d'
jsonが簡単に作成できるので作った
Webページの書式が定型で、json
をすぐに作れそうなので、作成しました。
$ curl -s https://raw.githubusercontent.com/syui/json-script/master/json/macbook-model.json
その他
system_profilerの検索
関係ありませんが、systeminfoはpecoとかで選択していくと便利そうです。
$ system_profiler -listdatatypes | peco | xargs system_profiler -detailLevel full -xml
最後に
もし年式が調べられるコマンドがあれば教えて下さい。また、データに不備があった場合も知らせてもらえると嬉しいです。
json
を置いて、スクリプトを実行するという形式については、セキュリティ上の懸念などがあるかもしれませんが、その辺り、おすすめの形式というか形態があれば教えて下さい。