Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Make a launchd agent instead' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Make a launchd agent instead
Authored by: Krioni on May 20, '07 08:21:38PM
Use Lingon to make a launchd agent that watches the system.log file. Have a shell script that sees if the change includes the phrase "posting notification com.apple.system.config.network_change"

If it does, the shell script can do whatever else you want, including run osascript to do some AppleScript commands.

Here's an example system.log watcher shell script:


#!/bin/sh

SEARCHSTRING="posting notification com.apple.system.config.network_change"
RECENTCHANGE=`tail -2 /var/log/system.log|grep "$SEARCHSTRING"`

LOGHEADER=`date +"%Y-%m-%d %H:%M:%S"`
HOSTNAME_SCRIPT=`hostname -s`
PROCESSNAME="NetworkChange"

if [ -z "$RECENTCHANGE" ] ; then 
# do nothing
else
   echo "$LOGHEADER $HOSTNAME_SCRIPT $PROCESSNAME: Network Changed">> /dev/console

fi

exit 0
On the line after the "echo...Network Changed" line, include the commands you want. The easiest way to do that if you know AppleScript is to make a script file and just call it like this:

osascript /PATH/TO/YOUR/SCRIPT.scpt 
Post here if you need more help getting that to work.

---
http://www.danshockley.com

[ Reply to This | # ]