Starting a new thread for this one…
SpiralOcean:
Thank you for the help on this regulus!
It’s exactly what I was looking for.
I have an applescript that I want to monitor network requests, if there is a network request, the location is switched from a location I have called ‘no connection’ to ‘automatic’. If no traffic has been generated for a specific amount of time, I want the location to switch back to ‘no connection’.
I’m envisioning this happening with another shell script.
Do you know where I can look for shell scripting help? Trying to go through all the commands based on the command name is not always informative. I’ve been searching around a bit, and haven’t found the information yet.
Any help is appreciated.
regulus6633:
This code switches between 2 network locations automatically. The 2 lines of importance are:
script “scselect 2>&1 | grep '^ ’ 2>&1 | grep ‘*’ | cut -f 2 -d ‘(’ | cut -f 1 -d ‘)’”
do shell script “scselect '” & loc_work & “'”
tells you the name of your current location and 2) will change your location. Then just use if/then statements to make it work for your situation. I don’t know how to make a new location other than GUI scripting.
-- change these 2 variables to the names of the 2 network loacations you want to switch between
set loc_home to "home" -- home is a name of one of my network locations
set loc_work to "work" -- work is a name of one of my network locations
set current_location to do shell script "scselect 2>&1 | grep '^ ' 2>&1 | grep '*' | cut -f 2 -d '(' | cut -f 1 -d ')'"
if current_location is loc_home then
do shell script "scselect '" & loc_work & "'"
delay 0.5
else
do shell script "scselect '" & loc_home & "'"
delay 0.5
end if
Camelot
December 30, 2007, 7:50pm
#2
IMHO this is beyond AppleScript’s ability.
Your script would have to monitor the network ports, which it can’t do.
There my be other applications that monitor the network and can invoke a script when activity is detected (Little Snitch, maybe?), but this is not something that AppleScript can do on its own.
Browser: Safari 523.1
Operating System: Mac OS X (10.5)