Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dikketienes

macrumors member
Original poster
Oct 13, 2008
64
0
Hi,

Is it possible to run an application when my mac connects to the internet.
For example: I have a simple applescript that I want to run when my Airport connects to the internet. The applescript mounts then my shared disks.

My first thought was a cron job but this will run every minute, that's a bit to much.

I hope you will have some suggestions.

Gr D
 
I take it you're trying to replicate Tiger's behavior with shared Airport disks. Have you looked to see if anyone has already implemented this? It's a dropped feature that has annoyed a lot of people.
 
If you know C programming you might be able to detect a connection via the SCNetworkReachability* API as it looks like it can do that.
 
Perhaps a long shot, but who knows: Some file must be modified in some way every time the Airport connects—for example, a system log. You could use the Finder (with the 'show system files option' and the view sorted by modification date) to try to find one such file.

Once you've done this, you could attach a folder action carrying out your desired tasks to the folder containing the aforementioned file.

How does this sound?
 
I am not quite sure I understand what you are looking for but I use a program called Marco Polo to connect all my SMB shares when I enter my local network at home. It works really well and is pretty configurable.

Basically what I do it this:
1. Watch for the SSID of my home wireless
2. When I see it switch to a predefined Network Location automatically
3. Delay for 5 seconds
4. Use the Marco Polo action to mount the share via SMB
 
If you know C programming you might be able to detect a connection via the SCNetworkReachability* API as it looks like it can do that.

An easy command-line system that probably uses this API is 'scutil -r', and alternative on this route is using the more advanced forms os scutil, namely something like:
Code:
scutil -r -W www.macrumors.com
This is going to take some parsing to get the results from, but if you monitor the output (a bit difficult in bash, but possible in python) then you could monitor things and launch whenever you need to. If you read the man page on scutil then you might get better ideas.

An alternate that would probably take a bit more work is to use crankd from the PyMacAdmin project. It is a bit to wade through, but once setup can be used to get callbacks when system properties change (like the network layout changing). Google has been using it on their engineer's Macs to tell when they are on the Google network or not and to adjust their AD settings accordingly.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.