6
6

More than 5 years have passed since last update.

MacBookの年式を調べるサービスを作った

Last updated at Posted at 2014-09-27

はじめに

サービスというか、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を置いて、スクリプトを実行するという形式については、セキュリティ上の懸念などがあるかもしれませんが、その辺り、おすすめの形式というか形態があれば教えて下さい。

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6