Display current network location via the Terminal

Sep 23, '04 10:18:00AM

Contributed by: Lathi

I make heavy usage of the Network Locations feature in OS X. It took me a lot of hunting to figure out (programatically) how to find my ocation. So after much work, here's a little Perl script that will return your location. I use this in shell scripts and Perl scripts to take actions conditional to my location.

#!/usr/bin/perl -w
use strict;

foreach (`scselect 2>&1`) {
    next unless /^\s*\*/;
    if (/\((\w+)/) {
        print "$1\n";
        exit;
    }
}

print "dunno\n";
Notice this is really just parsing the output of the scselect command. I haven't seen any documentation for this command, so I don't know if it's possible to do more with it.

Comments (13)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2004092010371018