Veteran Member
Join Date: May 2004
|
Okay, so for about, oh five *years* I've been missing the ability to have the Locations menu do more than just change the Network settings. (Yeah, Location X does it, but I'm a cheap-ass.) Well, I finally got off my butt today and did it.
I've been able to find all sorts of solutions for *changing* the Location based on other things, such as detected SSIDs, but I wanted the reverse of that. Change the Location, have it trigger *something* else. (Yes, you could write a script to do what you want, *and* change the Location, and trigger that from the Scripts menu, but I'm stubborn dammit.) The one solution I'd found for doing this involved editing Kicker.xml deep down in the guts of /System. I consider that a no-no. This is much cleaner. You have to be running 10.4 for this to work. Basically, it involves using launchd to watch a file, and when that file changes, run a script. Well, the file that you need to watch is /Library/Preferences/SystemConfiguration/preferences.plist. Toss the following text into a plist file saved in /Library/LaunchAgents/ and reboot. It'll run the script /Library/LaunchAgents/locchghook, and you can put whatever you want in there. Change the executable path if you like, to whatever you need it to be. Note that the script can be written in *sh, Python, Perl, AppleScript, or be a binary executable. Anything, really. Also, change the org.ncpod.locchghook to be the same as the root of your saved filename. ie, DoSomethingOnLocationChange.plist -> DoSomethingOnLocationChange Now, it'd be nice to have pre- and post- hooks for changing a Location (like quitting certain apps that need VPN access before changing the network, damn you Lotus) but this is a start at least. Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.ncpod.locchghook</string>
<key>OnDemand</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/Library/LaunchAgents/locchghook</string>
</array>
<key>ServiceDescription</key>
<string>Location Change Hook</string>
<key>WatchPaths</key>
<array>
<string>/Library/Preferences/SystemConfiguration/preferences.plist</string>
</array>
</dict>
</plist> |
quote |
Posting Rules | Navigation |
|
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
What are the dates for Apple Events this year? | JFerraro | Speculation and Rumors | 3 | 2006-03-28 13:14 |
Where were you when you first heard about the events of 9/11/01? | Windswept | AppleOutsider | 42 | 2005-03-30 15:51 |