MacOSXのコマンドからGoogleトランジット
前の記事で、ブラウザをコマンドから立ち上げてurlを渡してみました。
その要領でGoogle Mapsの乗換案内を使ったスクリプトを作ってみました。
以下のような感じでコマンドを叩くと、ブラウザで検索結果が見られます。
終電検索は last の"l"を使います。
trans -l 新宿 片瀬江ノ島
8/20の18:00に渋谷に着きたいなら
trans -a 18:00 -D 08/20 片瀬江ノ島 渋谷
という感じで使えて、なかなか便利です。ヘルプは-hオプションで。
USAGE: [-(l|a|d)] from to
-D, yy/mm/dd
-l, 終電検索
-a hh:mm, 到着時間で検索
-d hh:mm, 出発時刻で検索
-0, 特急、飛行機なし
-h, Show this help.
以下transコマンドの中身です。openコマンドでブラウザを開けるのはMacならではです。
#!/bin/sh Browser="Google Chrome.app" function show_usage { echo "USAGE: $CMDNAME [-(l|a|d)] from to " echo " -D, yy/mm/dd" echo " -l, 終電検索" echo " -a hh:mm, 到着時間で検索" echo " -d hh:mm, 出発時刻で検索" echo " -0, 特急、飛行機なし" echo " -h, Show this help." exit 1 } noal=0 noexp=0 date="" time="" ttype=now saddr=$SADDR daddr=$DADDR sort=time while getopts D:la:d:0h OPT do #echo $OPT #echo $OPTARG case $OPT in l ) ttype=last ;; a ) ttype=arr; time=$OPTARG ;; d ) ttype=dep; time=$OPTARG ;; D ) date=$OPTARG ;; 0 ) noexp=1; noal=1 ;; h ) show_usage ;; esac done shift $(expr $OPTIND - 1) test $# -ne 2 && show_usage saddr=$1 daddr=$2 url="http://maps.google.co.jp/maps?saddr=$saddr&daddr=$daddr"; url=${url}"&ttype=$ttype&noexp=$noexp&noal=$noal" test $date && url="${url}&date=$(echo $date)" test $time && url="${url}&time=$time" $inet "$url" open -a /Applications/"$Browser" "$url"