Run application when detects internet?

Discussion in 'Mac Programming' started by dikketienes, Dec 12, 2009.

  1. dikketienes macrumors member

    Joined:
    Oct 13, 2008
    #1
    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
     
  2. Detrius macrumors 68000

    Joined:
    Sep 10, 2008
    Location:
    Asheville, NC
    #2
    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.
     
  3. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #3
    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.
     
  4. Macula macrumors 6502

    Macula

    Joined:
    Oct 23, 2006
    Location:
    All over the place
    #4
    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?
     
  5. prostuff1 macrumors 65816

    prostuff1

    Joined:
    Jul 29, 2005
    Location:
    Don't step into the kawoosh...
    #5
    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
     
  6. larkost macrumors 6502a

    Joined:
    Oct 13, 2007
    #6
    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.
     

Share This Page