Skip to content

Instantly share code, notes, and snippets.

@scott0228
Created July 25, 2012 11:40

Revisions

  1. scott0228 created this gist Jul 25, 2012.
    23 changes: 23 additions & 0 deletions autolocation.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #!/bin/bash
    # 先取得 SSID
    ssid=$(networksetup -getairportnetwork en1 | cut -c 24-)

    # 依 SSID 決定要用哪個 location ,可利用 scselect 指令來列出所有的 location
    if [ $ssid = "ScottAP" ]
    then
    location="Work"
    else
    location="Automatic"
    fi

    # 更新 location
    newloc=`/usr/sbin/scselect ${location} | sed 's/^.*(\(.*\)).*$/\1/'`
    echo ${newloc}

    # 辨斷是否正確來回撌值
    if [ ${location} != ${newloc} ]
    then
    exit 1
    fi

    exit 0