|
|
Need location-change triggered events
I'm a big user of the network locations in Mac OS X, it's really a life saver.
I also wanted to have events (not totally dissimilar to the examples you mentioned) triggered by changing locations. I remembered that I saw an article for a "dirty little script" that would change the smtp server for Mail.app when you changed locations. That stuff can be found here.
The only problem is that I tried several times to edit my Kicker.xml file (see site linked above for full instructions) which is supposed to be able run a script based on the location changing, but I could never get it to work. I only tried for a little while and haven't gone back since. My suspicion was that it was a Jaguar related change (I was trying this stuff just after 10.2 was released).
Anyway, I tunnel my mail traffic via ssh back to my home server and besides I have a .mac account so I can safely use their smtp server no matter what network I join, so I don't need everything from the site above. However, I could really use the capability to run certain scripts based on location. Basically | just ripped out the perl that queries the system for the current location: (note this is pretty much a copy from the site above, oh and I don't know perl yet, so it may be crappy code but it hasn't failed me so far.)
#!/usr/bin/perl -w # ------------------------------------------------------------------------------ # getLocation.pl written by Christopher Copeland 2002-09-02 # modified from script at http://interconnected.org/src/autosmtp/ # simple perl script that prints the current location # ------------------------------------------------------------------------------ use strict; my $location = &get_location_from_scutil() || ""; sub get_location_from_scutil { my @scutil = `scutil /dev/null open show Setup:/ close end_scutil`; my @matches = map { m/UserDefinedName : (.*)/ } @scutil; if(@matches == 1) { return $matches[0]; } else { return undef; } } print $locationSo now I have getLocation.pl in my ~/bin/ and I use it all the time from other scripts. I've got a cron job that runs every 30 minutes and based on what location is returned by getLocation.pl, I can perform certain actions like rsync my files, starting apps or anything you might need doing. It would be cleaner if the scripts ran as a result of the Kicker noticing a location change, so I'll try to get that working over the holidays, but for now cron and the script above work well enough for my needs.
Need location-change triggered events
or you could have done it in a one liner: |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:Hints1 new Hints in the last 24 hoursComments last 2 daysNo new commentsLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.09 seconds |
|